diff --git a/nifti2/nifti_tool.c b/nifti2/nifti_tool.c index ac249bf8..f964d099 100644 --- a/nifti2/nifti_tool.c +++ b/nifti2/nifti_tool.c @@ -2843,7 +2843,7 @@ int act_diff_nims( nt_opts * opts ) if( ! nim0 ) return 1; /* errors have been printed */ nim1 = nt_image_read(opts, opts->infiles.list[1], 0, 0); - if( ! nim1 ){ free(nim0); return 1; } + if( ! nim1 ){ nifti_image_free(nim0); return 1; } if( g_debug > 1 ) fprintf(stderr,"\n-d nifti_image diffs between '%s' and '%s'...\n", @@ -3359,6 +3359,7 @@ int act_mod_hdrs( nt_opts * opts ) if( !nim ) { fprintf(stderr,"** failed to dup file '%s' before modifying\n", fname); + free(nhdr); return 1; } @@ -3369,6 +3370,7 @@ int act_mod_hdrs( nt_opts * opts ) { NTL_FERR(func,"failed to set prefix for new file: ",opts->prefix); nifti_image_free(nim); + free(nhdr); return 1; } dupname = nifti_strdup(nim->fname); /* so we know to free it */ @@ -3377,6 +3379,8 @@ int act_mod_hdrs( nt_opts * opts ) if( nifti_image_write_status(nim) ) { fprintf(stderr,"** failed to write image %s\n", nim->fname); nifti_image_free(nim); + free(dupname); + free(nhdr); return 1; } @@ -3477,6 +3481,7 @@ int act_mod_hdr2s( nt_opts * opts ) if( !nim ) { fprintf(stderr,"** failed to dup file '%s' before modifying\n", fname); + free(nhdr); return 1; } if( opts->keep_hist && nifti_add_extension(nim, opts->command, @@ -3486,6 +3491,7 @@ int act_mod_hdr2s( nt_opts * opts ) { NTL_FERR(func,"failed to set prefix for new file: ",opts->prefix); nifti_image_free(nim); + free(nhdr); return 1; } dupname = nifti_strdup(nim->fname); /* so we know to free it */ @@ -3494,6 +3500,8 @@ int act_mod_hdr2s( nt_opts * opts ) if( nifti_image_write_status(nim) ) { fprintf(stderr,"** failed to write image %s\n", nim->fname); nifti_image_free(nim); + free(dupname); + free(nhdr); return 1; } @@ -3623,6 +3631,7 @@ int act_swap_hdrs( nt_opts * opts ) if( !nim ) { fprintf(stderr,"** failed to dup file '%s' before modifying\n", fname); + free(nhdr); return 1; } if( opts->keep_hist && nifti_add_extension(nim, opts->command, @@ -3632,6 +3641,7 @@ int act_swap_hdrs( nt_opts * opts ) { NTL_FERR(func,"failed to set prefix for new file: ",opts->prefix); nifti_image_free(nim); + free(nhdr); return 1; } dupname = nifti_strdup(nim->fname); /* so we know to free it */ @@ -3640,6 +3650,8 @@ int act_swap_hdrs( nt_opts * opts ) if( nifti_image_write_status(nim) ) { fprintf(stderr,"** failed to write image %s\n", nim->fname); nifti_image_free(nim); + free(dupname); + free(nhdr); return 1; } diff --git a/niftilib/nifti1_tool.c b/niftilib/nifti1_tool.c index 15bb165a..5588b9c4 100644 --- a/niftilib/nifti1_tool.c +++ b/niftilib/nifti1_tool.c @@ -2277,7 +2277,7 @@ int act_diff_nims( nt_opts * opts ) if( ! nim0 ) return 1; /* errors have been printed */ nim1 = nt_image_read(opts, opts->infiles.list[1], 0); - if( ! nim1 ){ free(nim0); return 1; } + if( ! nim1 ){ nifti_image_free(nim0); return 1; } if( g_debug > 1 ) fprintf(stderr,"\n-d nifti_image diffs between '%s' and '%s'...\n", @@ -2606,6 +2606,7 @@ int act_mod_hdrs( nt_opts * opts ) if( !nim ) { fprintf(stderr,"** failed to dup file '%s' before modifying\n", fname); + free(nhdr); return 1; } if( opts->keep_hist && nifti_add_extension(nim, opts->command, @@ -2615,6 +2616,7 @@ int act_mod_hdrs( nt_opts * opts ) { NTL_FERR(func,"failed to set prefix for new file: ",opts->prefix); nifti_image_free(nim); + free(nhdr); return 1; } dupname = nifti_strdup(nim->fname); /* so we know to free it */ @@ -2623,6 +2625,8 @@ int act_mod_hdrs( nt_opts * opts ) if( nifti_image_write_status(nim) ) { fprintf(stderr,"** failed to write image %s\n", nim->fname); nifti_image_free(nim); + free(dupname); + free(nhdr); return 1; } @@ -2727,6 +2731,7 @@ int act_swap_hdrs( nt_opts * opts ) if( !nim ) { fprintf(stderr,"** failed to dup file '%s' before modifying\n", fname); + free(nhdr); return 1; } if( opts->keep_hist && nifti_add_extension(nim, opts->command, @@ -2736,6 +2741,7 @@ int act_swap_hdrs( nt_opts * opts ) { NTL_FERR(func,"failed to set prefix for new file: ",opts->prefix); nifti_image_free(nim); + free(nhdr); return 1; } dupname = nifti_strdup(nim->fname); /* so we know to free it */ @@ -2744,6 +2750,8 @@ int act_swap_hdrs( nt_opts * opts ) if( nifti_image_write_status(nim) ) { fprintf(stderr,"** failed to write image %s\n", nim->fname); nifti_image_free(nim); + free(dupname); + free(nhdr); return 1; }