diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index 58b20841..43a26f71 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -8826,9 +8826,11 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) nim->nifti_type = NIFTI_FTYPE_NIFTI2_2 ; } else if( strcmp(lhs,"header_filename") == 0 ){ + free(nim->fname) ; /* the attribute may appear more than once */ nim->fname = nifti_strdup(rhs) ; } else if( strcmp(lhs,"image_filename") == 0 ){ + free(nim->iname) ; nim->iname = nifti_strdup(rhs) ; } else if( strcmp(lhs,"sto_xyz_matrix") == 0 ){ diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index 1992b188..0580c629 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -6706,9 +6706,11 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) nim->nifti_type = NIFTI_FTYPE_ASCII ; } else if( strcmp(lhs,"header_filename") == 0 ){ + free(nim->fname) ; /* the attribute may appear more than once */ nim->fname = nifti_strdup(rhs) ; } else if( strcmp(lhs,"image_filename") == 0 ){ + free(nim->iname) ; nim->iname = nifti_strdup(rhs) ; } else if( strcmp(lhs,"sto_xyz_matrix") == 0 ){