Skip to content
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
20 changes: 18 additions & 2 deletions cifti/afni_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,14 @@ afni_xml_t * new_afni_xml(const char * name)
newp->xparent = NULL;
newp->xchild = NULL;

if( name ) newp->name = strdup(name);
if( name ) {
newp->name = strdup(name);
if( ! newp->name ) {
fprintf(stderr,"** new_afni_xml: failed to copy name '%s'\n", name);
free(newp);
return NULL;
}
}

return newp;
}
Expand Down Expand Up @@ -457,6 +464,11 @@ int axml_add_attrs(afni_xml_t * ax, const char ** attr)
for(c = 0, aind = 0; attr[c]; c += 2, aind++) {
ax->attrs.name[aind] = strdup(strip_whitespace(attr[c],0));
ax->attrs.value[aind] = strdup(strip_whitespace(attr[c+1],0));
if( ! ax->attrs.name[aind] || ! ax->attrs.value[aind] ) {
fprintf(stderr,"** NAX: failed to copy attribute %d\n", aind);
ax->attrs.length = aind+1; /* so the partial pair is still freed */
return 1;
}
}

return 0;
Expand Down Expand Up @@ -838,7 +850,11 @@ static afni_xml_t * make_afni_xml(const char * ename, const char ** attr)
newp = new_afni_xml(ename);
if( ! newp ) return NULL;

axml_add_attrs(newp, attr);
/* a failure here is an allocation failure; epush() skips on NULL */
if( axml_add_attrs(newp, attr) ) {
axml_free_xml_t(newp);
return NULL;
}

return newp;
}
Expand Down
4 changes: 4 additions & 0 deletions nifti2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ if(NIFTI_BUILD_TESTING AND NIFTI_BUILD_APPLICATIONS)
add_test( NAME ${TEST_PREFIX}_nii_cmp_selftest COMMAND sh ${NIFTI_TEST_SCRIPT_DIR}/nii_cmp_selftest.sh ${NIFTI_TEST_SCRIPT_DIR} )
endif()

# Reading an ASCII header through the NIFTI-2 reader releases the image
# it built; the leak is what the memcheck and sanitizer legs observe.
add_test( NAME ${TEST_PREFIX}_tool_disp_hdr2_ascii COMMAND $<TARGET_FILE:${TOOL_NAME}> -disp_hdr2 -infiles ${CMAKE_CURRENT_LIST_DIR}/testdata/dup_attr.nia )

unset(TEST_SUFFIX)
unset(TEST_PREFIX)
unset(TOOL_NAME)
Expand Down
7 changes: 6 additions & 1 deletion nifti2/nifti2_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -5492,8 +5492,13 @@ nifti_2_header * nifti_read_n2_hdr(const char * hname, int * swapped,
if( ! nim ) return NULL;

hptr = (nifti_2_header *)malloc(sizeof(nifti_2_header));
if( ! hptr ){
fprintf(stderr,"** nifti_read_n2_hdr: failed to alloc nifti_2_header\n");
nifti_image_free(nim);
return NULL;
}
rv = nifti_convert_nim2n2hdr(nim, hptr);
free(nim);
nifti_image_free(nim); /* free(nim) leaked nim's filename strings */

if( rv ) { free(hptr); return NULL; }
return hptr;
Expand Down
Loading