when we free() something, always set it to NULL.

git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@3907 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Fredrik
2002-01-16 08:51:05 +00:00
parent cb171cb395
commit 65717c81e5
3 changed files with 13 additions and 0 deletions

View File

@@ -942,6 +942,7 @@ canon_int_list_directory (Camera *camera, const char *folder, CameraList *list,
"initial message too short (%i < minimum %i)",
dirents_length, CANON_MINIMUM_DIRENT_SIZE);
free (dirent_data);
dirent_data = NULL;
return GP_ERROR;
}
@@ -962,6 +963,7 @@ canon_int_list_directory (Camera *camera, const char *folder, CameraList *list,
"Reached end of packet while "
"examining the first dirent");
free (dirent_data);
dirent_data = NULL;
return GP_ERROR;
}
pos++; /* skip NULL byte terminating directory name */
@@ -1026,6 +1028,7 @@ canon_int_list_directory (Camera *camera, const char *folder, CameraList *list,
"canon_int_list_dir: "
"truncated directory entry encountered");
free (dirent_data);
dirent_data = NULL;
return GP_ERROR;
}
@@ -1166,6 +1169,7 @@ canon_int_list_directory (Camera *camera, const char *folder, CameraList *list,
pos += dirent_ent_size;
}
free (dirent_data);
dirent_data = NULL;
GP_DEBUG ("<FILESYSTEM-DUMP>");
gp_filesystem_dump (camera->fs);
@@ -1335,6 +1339,7 @@ canon_int_get_thumbnail (Camera *camera, const char *name, unsigned char **retda
if (res != GP_OK) {
GP_DEBUG ("canon_int_get_thumbnail: couldn't extract thumbnail data");
free (data);
data = NULL;
return res;
}
GP_DEBUG ("canon_int_get_thumbnail: extracted thumbnail data");
@@ -1513,6 +1518,8 @@ old_canon_int_get_thumbnail (Camera *camera, const char *name, int *length)
}
free (data);
data = NULL;
return NULL;
}
#endif

View File

@@ -982,6 +982,7 @@ canon_serial_get_file (Camera *camera, const char *name, int *length, GPContext
msg = canon_serial_recv_msg (camera, 0x1, 0x21, &len, context);
}
free (file);
file = NULL;
return NULL;
}
@@ -1046,6 +1047,7 @@ canon_serial_get_dirents (Camera *camera, unsigned char **dirent_data,
gp_context_error (context, "canon_serial_get_dirents: "
"Failed to read another directory entry");
free (data);
data = NULL;
return GP_ERROR;
}
@@ -1061,6 +1063,7 @@ canon_serial_get_dirents (Camera *camera, unsigned char **dirent_data,
gp_context_error (context, "canon_serial_get_dirents: "
"Truncated directory entry received");
free (data);
data = NULL;
return GP_ERROR;
}
@@ -1086,6 +1089,7 @@ canon_serial_get_dirents (Camera *camera, unsigned char **dirent_data,
gp_context_error (context, "canon_serial_get_dirents: "
"Too many dirents, we must be looping.");
free (data);
data = NULL;
return GP_ERROR;
}
@@ -1096,6 +1100,7 @@ canon_serial_get_dirents (Camera *camera, unsigned char **dirent_data,
"Could not resize dirent buffer "
"to %i bytes", mallocd_bytes);
free (data);
data = NULL;
return GP_ERROR;
}
data = temp_ch;

View File

@@ -597,6 +597,7 @@ canon_usb_long_dialogue (Camera *camera, int canon_funct, unsigned char **data,
"gp_port_read() returned error (%i) or no data\n",
bytes_read);
free (*data);
*data = NULL;
/* here, it is an error to get 0 bytes from gp_port_read()
* too, but 0 is GP_OK so if bytes_read is 0 return GP_ERROR_CORRUPTED_DATA