check some NULL ptr returns from strdup, malloc

git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@9992 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Marcus Meissner
2007-02-07 17:49:31 +00:00
parent df8211bea9
commit 29bcee8b7a
4 changed files with 19 additions and 0 deletions

View File

@@ -491,6 +491,8 @@ _put_STR(CONFIG_PUT_ARGS) {
if (ret != GP_OK)
return ret;
propval->str = strdup (string);
if (!propval->str)
return (GP_ERROR_NO_MEMORY);
return (GP_OK);
}
@@ -505,6 +507,8 @@ _put_AUINT8_as_CHAR_ARRAY(CONFIG_PUT_ARGS) {
memset(propval,0,sizeof(PTPPropertyValue));
/* add \0 ? */
propval->a.v = malloc((strlen(value)+1)*sizeof(PTPPropertyValue));
if (!propval->a.v)
return (GP_ERROR_NO_MEMORY);
propval->a.count = strlen(value)+1;
for (i=0;i<strlen(value)+1;i++)
propval->a.v[i].u8 = value[i];
@@ -645,6 +649,8 @@ _put_ImageSize(CONFIG_PUT_ARGS) {
if(ret != GP_OK)
return ret;
propval->str = strdup (value);
if (!propval->str)
return (GP_ERROR_NO_MEMORY);
return(GP_OK);
}
@@ -1621,6 +1627,8 @@ _put_STR_as_time(CONFIG_PUT_ARGS) {
/* 20020101T123400.0 is returned by the HP Photosmart */
sprintf(asctime,"%04d%02d%02dT%02d%02d%02d.0",pxtm->tm_year+1900,pxtm->tm_mon+1,pxtm->tm_mday,pxtm->tm_hour,pxtm->tm_min,pxtm->tm_sec);
propval->str = strdup(asctime);
if (!propval->str)
return (GP_ERROR_NO_MEMORY);
return (GP_OK);
}

View File

@@ -136,6 +136,8 @@ add_special_file (char *name, getfunc_t getfunc, putfunc_t putfunc) {
special_files = malloc (sizeof(special_files[0]));
special_files[nrofspecial_files].name = strdup(name);
if (!special_files[nrofspecial_files].name)
return (GP_ERROR_NO_MEMORY);
special_files[nrofspecial_files].putfunc = putfunc;
special_files[nrofspecial_files].getfunc = getfunc;
nrofspecial_files++;
@@ -2548,6 +2550,8 @@ ptp_mtp_parse_metadata (
*end = '\0';
content = strdup(begin);
*end = '<';
if (!content)
continue;
gp_log (GP_LOG_DEBUG, "ptp2", "found tag %s, content %s", propname, content);
ret = ptp_mtp_getobjectpropdesc (params, props[j], ofc, &opd);
if (ret != PTP_RC_OK) {

View File

@@ -597,6 +597,8 @@ ptp_ptpip_connect (PTPParams* params, const char *address) {
if (NULL == strchr (address,':'))
return GP_ERROR_BAD_PARAMETERS;
addr = strdup (address);
if (!addr)
return GP_ERROR_NO_MEMORY;
s = strchr (addr,':'); *s = '\0';
p = strchr (s+1,':');
port = 15740;

View File

@@ -143,6 +143,8 @@ ptp_usb_senddata (PTPParams* params, PTPContainer* ptp,
if (usecontext)
progressid = gp_context_progress_start (context, (size/CONTEXT_BLOCK_SIZE), _("Uploading..."));
bytes = malloc (4096);
if (!bytes)
return PTP_RC_GeneralError;
/* if everything OK send the rest */
bytes_left_to_transfer = size-datawlen;
ret = PTP_RC_OK;
@@ -248,6 +250,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
}
if (usbdata.length == 0xffffffffU) {
unsigned char *data = malloc (PTP_USB_BULK_HS_MAX_PACKET_LEN);
if (!data) return PTP_RC_GeneralError;
/* stuff data directly to passed data handler */
while (1) {
unsigned long written;
@@ -281,6 +284,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
if (surplen >= PTP_USB_BULK_HDR_LEN) {
params->response_packet = malloc(surplen);
if (!params->response_packet) return PTP_RC_GeneralError;
memcpy(params->response_packet,
(uint8_t *) &usbdata + packlen, surplen);
params->response_packet_size = surplen;
@@ -313,6 +317,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
retry:
oldsize = 0;
data = malloc(READLEN);
if (!data) return PTP_RC_GeneralError;
bytes_to_read = len - (rlen - PTP_USB_BULK_HDR_LEN);
usecontext = (bytes_to_read > CONTEXT_BLOCK_SIZE);
ret = PTP_RC_OK;