Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary if (not-null) check before calling free() #1001

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions camlibs/aox/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,8 @@ camera_exit (Camera *camera, GPContext *context)
{
GP_DEBUG ("Aox camera_exit");

if (camera->pl) {
free (camera->pl);
camera->pl = NULL;
}
free (camera->pl);
camera->pl = NULL;

return GP_OK;
}
Expand Down
3 changes: 1 addition & 2 deletions camlibs/ax203/ax203_decode_yuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ main(int argc, char *argv[])
fclose (fin);
if (fout)
fclose (fout);
if (buf)
free (buf);
free (buf);
if (im)
gdImageDestroy (im);
if (im_in)
Expand Down
3 changes: 1 addition & 2 deletions camlibs/canon/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,7 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
}
if (ret != GP_OK) {
GP_DEBUG ("get_file_func: GP_FILE_TYPE_PREVIEW: couldn't extract JPEG thumbnail data");
if (data)
free (data);
free (data);
data = NULL;
return ret;
}
Expand Down
18 changes: 6 additions & 12 deletions camlibs/canon/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2282,8 +2282,7 @@ canon_usb_put_file (Camera *camera, CameraFile *file,
if (status != 0x40) {
GP_DEBUG ("canon_put_file_usb: write 1 failed! (returned %i)", status);
gp_context_error(context, _("File upload failed."));
if(newdata)
free(newdata);
free(newdata);
free(packet);
return GP_ERROR_CORRUPTED_DATA;
}
Expand All @@ -2293,8 +2292,7 @@ canon_usb_put_file (Camera *camera, CameraFile *file,
GP_DEBUG ("canon_put_file_usb: read 1 failed! "
"(returned %i, expected %i)", status, 0x40);
gp_context_error(context, _("File upload failed."));
if(newdata)
free(newdata);
free(newdata);
free(packet);
return GP_ERROR_CORRUPTED_DATA;
}
Expand Down Expand Up @@ -2329,8 +2327,7 @@ canon_usb_put_file (Camera *camera, CameraFile *file,
GP_DEBUG ("canon_put_file_usb: write 2 failed! "
"(returned %i, expected %li)", status, len1+0x40);
gp_context_error(context, _("File upload failed."));
if(newdata)
free(newdata);
free(newdata);
free(packet);
if ( status < 0 )
return GP_ERROR_OS_FAILURE;
Expand All @@ -2343,8 +2340,7 @@ canon_usb_put_file (Camera *camera, CameraFile *file,
GP_DEBUG ("canon_put_file_usb: read 2 failed! "
"(returned %i, expected %i)", status, 0x5c);
gp_context_error(context, _("File upload failed."));
if(newdata)
free(newdata);
free(newdata);
free(packet);
if ( status < 0 )
return GP_ERROR_OS_FAILURE;
Expand All @@ -2357,8 +2353,7 @@ canon_usb_put_file (Camera *camera, CameraFile *file,
GP_DEBUG ("canon_put_file_usb: read 3 failed! "
"(returned %i, expected %i)", status, 0x5c);
gp_context_error(context, _("File upload failed."));
if(newdata)
free(newdata);
free(newdata);
free(packet);
if ( status < 0 )
return GP_ERROR_OS_FAILURE;
Expand All @@ -2385,8 +2380,7 @@ canon_usb_put_file (Camera *camera, CameraFile *file,
gp_context_message(context, _("File was too big. You may have to turn your camera off and back on before uploading more files."));
}

if(newdata)
free(newdata);
free(newdata);
free(packet);
return GP_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion camlibs/casio/casio-qv-commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ QVblockrecv (Camera *camera, unsigned char **buf, unsigned long int *buf_len)
/* Allocate the memory */
new = (unsigned char*)realloc (*buf, sizeof (char) * (*buf_len + size));
if (new == (unsigned char*)0) {
if (*buf != (unsigned char*)0) free(*buf);
free(*buf);
return (GP_ERROR_NO_MEMORY);
}
*buf = new;
Expand Down
3 changes: 1 addition & 2 deletions camlibs/digita/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ int digita_get_file_list(CameraPrivateLibrary *dev)
goto end;
}

if (dev->file_list)
free(dev->file_list);
free(dev->file_list);

dev->file_list = malloc(taken * sizeof(struct file_item));
if (!dev->file_list) {
Expand Down
6 changes: 2 additions & 4 deletions camlibs/fuji/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,8 @@ static const struct {
static int
camera_exit (Camera *camera, GPContext *context)
{
if (camera->pl) {
free (camera->pl);
camera->pl = NULL;
}
free (camera->pl);
camera->pl = NULL;

return (GP_OK);
}
Expand Down
12 changes: 4 additions & 8 deletions camlibs/gsmart300/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,10 @@ static int
camera_exit (Camera *camera, GPContext *context)
{
if (camera->pl) {
if (camera->pl->fats) {
free (camera->pl->fats);
camera->pl->fats = NULL;
}
if (camera->pl->files) {
free (camera->pl->files);
camera->pl->files = NULL;
}
free (camera->pl->fats);
camera->pl->fats = NULL;
free (camera->pl->files);
camera->pl->files = NULL;

free (camera->pl);
camera->pl = NULL;
Expand Down
7 changes: 3 additions & 4 deletions camlibs/jl2005a/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,9 @@ camera_exit (Camera *camera, GPContext *context)
GP_DEBUG ("jl2005a camera_exit");
jl2005a_reset(camera, camera->port);
gp_port_close(camera->port);
if (camera->pl) {
free (camera->pl);
camera->pl = NULL;
}
free (camera->pl);
camera->pl = NULL;

return GP_OK;
}

Expand Down
6 changes: 2 additions & 4 deletions camlibs/lg_gsm/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,8 @@ camera_exit (Camera *camera, GPContext *context)
{
GP_DEBUG ("LG GSM camera_exit");

if (camera->pl) {
free (camera->pl);
camera->pl = NULL;
}
free (camera->pl);
camera->pl = NULL;

return GP_OK;
}
Expand Down
7 changes: 3 additions & 4 deletions camlibs/mars/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,9 @@ camera_exit (Camera *camera, GPContext *context)
GP_DEBUG ("Mars camera_exit");
mars_reset(camera->port);
gp_port_close(camera->port);
if (camera->pl) {
free (camera->pl);
camera->pl = NULL;
}
free (camera->pl);
camera->pl = NULL;

return GP_OK;
}

Expand Down
8 changes: 2 additions & 6 deletions camlibs/minolta/dimagev/capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,12 @@ int dimagev_shutter(dimagev_t *dimagev) {
if ( gp_port_write(dimagev->dev, (char *)p->buffer, p->length) < GP_OK ) {
GP_DEBUG( "dimagev_shutter::unable to write packet");

if ( p != NULL ) {
free(p);
}
free(p);

return GP_ERROR_IO;
}

if ( p != NULL ) {
free(p);
}
free(p);


if ( sleep(1) != 0 ) {
Expand Down
3 changes: 1 addition & 2 deletions camlibs/mustek/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ int mdc800_openCamera (Camera *camera)

int mdc800_closeCamera (Camera *camera)
{
if (camera->pl) {
free(camera->pl);
camera->pl = NULL;
}

return GP_OK;
}

Expand Down
6 changes: 2 additions & 4 deletions camlibs/panasonic/coolshot/coolshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,8 @@ static int get_info_func (CameraFilesystem *fs, const char *folder,

static int camera_exit (Camera *camera, GPContext *context)
{
if (camera->pl) {
free (camera->pl);
camera->pl = NULL;
}
free (camera->pl);
camera->pl = NULL;

return (GP_OK);
}
Expand Down
6 changes: 2 additions & 4 deletions camlibs/panasonic/dc1580.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,8 @@ int camera_abilities (CameraAbilitiesList *list) {
static int camera_exit (Camera *camera, GPContext *context) {
gp_context_status(context, _("Disconnecting camera."));
dsc2_disconnect(camera);
if (camera->pl->buf) {
free (camera->pl->buf);
camera->pl->buf = NULL;
}
free (camera->pl->buf);
camera->pl->buf = NULL;
free (camera->pl);
camera->pl = NULL;
return (GP_OK);
Expand Down
6 changes: 2 additions & 4 deletions camlibs/polaroid/pdc640.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,10 +975,8 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *file,
static int
camera_exit (Camera *camera, GPContext *context)
{
if (camera->pl) {
free (camera->pl);
camera->pl = NULL;
}
free (camera->pl);
camera->pl = NULL;

return (GP_OK);
}
Expand Down
2 changes: 1 addition & 1 deletion camlibs/ptp2/ptp-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -3291,7 +3291,7 @@ ptp_unpack_ptp11_manifest (
return 1;
tooshort:
for (i = 0; i < numberoifs; i++)
if (xoifs[i].Filename) free (xoifs[i].Filename);
free (xoifs[i].Filename);
free (xoifs);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion camlibs/ptp2/ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ ptp_olympus_init_pc_mode (PTPParams* params)
//ptp_debug (params,"PTP: (Olympus Init) getting response...");
//gp_port_set_timeout (camera->port, timeout);
//ret=ptp_transaction(params, &ptp, PTP_DP_RESPONSEONLY, size, &data, NULL);
//if(data) free(data);
//free(data);
return ret;
}

Expand Down
18 changes: 9 additions & 9 deletions camlibs/ricoh/g3.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ g3_cwd_command( GPPort *port, const char *folder) {
ret = g3_ftp_command_and_reply(port, cmd, &reply);
free(cmd);
if (ret < GP_OK) {
if (reply) free(reply);
free(reply);
return ret;
}
if (reply[0]=='5') /* Failed, most likely no such directory */
Expand Down Expand Up @@ -421,8 +421,8 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
buf = NULL; /* now owned by libgphoto2 filesystem */

out:
if (buf) free(buf);
if (reply) free(reply);
free(buf);
free(reply);
return (GP_OK);
}

Expand Down Expand Up @@ -460,8 +460,8 @@ put_file_func (CameraFilesystem *fs, const char *folder, const char *fn, CameraF
ret = g3_channel_read(camera->port, &channel, &reply, &len); /* reply */
if (ret < GP_OK) goto out;
out:
if (buf) free(buf);
if (reply) free(reply);
free(buf);
free(reply);
return (GP_OK);
}
#endif
Expand Down Expand Up @@ -771,8 +771,8 @@ folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
ret = GP_ERROR_IO;
}
out:
if (buf) free(buf);
if (reply) free(reply);
free(buf);
free(reply);
return ret;
}

Expand Down Expand Up @@ -872,8 +872,8 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
ret = GP_ERROR_IO;
}
out:
if (buf) free(buf);
if (reply) free(reply);
free(buf);
free(reply);
return (GP_OK);
}

Expand Down
6 changes: 2 additions & 4 deletions camlibs/ricoh/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ camera_abilities (CameraAbilitiesList *list)
static int
camera_exit (Camera *camera, GPContext *context)
{
if (camera->pl) {
free (camera->pl);
camera->pl = NULL;
}
free (camera->pl);
camera->pl = NULL;

ricoh_disconnect (camera, context);

Expand Down
4 changes: 2 additions & 2 deletions camlibs/soundvision/agfa_cl18.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int agfa_delete_picture(CameraPrivateLibrary *dev, const char *filename) {
return ret;
}

if (dev->file_list) free(dev->file_list);
free(dev->file_list);
dev->file_list = (char *)buffer;

ret=soundvision_send_command(SOUNDVISION_GET_PIC_SIZE,0,dev);
Expand Down Expand Up @@ -221,7 +221,7 @@ int agfa_get_file_list(CameraPrivateLibrary *dev) {
return GP_ERROR_CORRUPTED_DATA;
}

if (dev->file_list) free(dev->file_list);
free(dev->file_list);

dev->file_list = malloc(taken * 13);
if (!dev->file_list) {
Expand Down
2 changes: 1 addition & 1 deletion camlibs/soundvision/soundvision.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static int soundvision_file_get (Camera *camera, const char *filename, int thumb

file_get_error:

if (*data!=NULL) free(*data);
free(*data);
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions camlibs/soundvision/tiger_fastflicks.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int tiger_upload_file(CameraPrivateLibrary *dev,
return GP_OK;

upload_error:
if (our_data!=NULL) free(our_data);
free(our_data);
GP_DEBUG("Error in tiger_upload_file");
return result;
}
Expand Down Expand Up @@ -317,7 +317,7 @@ int tiger_get_file_list(CameraPrivateLibrary *dev) {
}


if (dev->file_list) free(dev->file_list);
free(dev->file_list);

dev->file_list = malloc(taken * 13);

Expand Down Expand Up @@ -350,7 +350,7 @@ int tiger_get_file_list(CameraPrivateLibrary *dev) {

list_files_error:

if (buffer!=NULL) free(buffer);
free(buffer);
return ret;
}

Expand Down
Loading
Loading