Memory Leak in ncmpii_NC_findattr() (attr.m4 line 301)

Sjaardema, Gregory D gdsjaar at sandia.gov
Tue Jul 14 11:11:40 CDT 2015


In attr.m4, is the following code:

int
ncmpii_NC_findattr(const NC_attrarray *ncap,
                   const char         *uname)
{
    int i;
    size_t nchars;

    assert(ncap != NULL);

    char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
    nchars = strlen(name);

    if (ncap->ndefined == 0) return -1; /* none created yet */

    for (i=0; i<ncap->ndefined; i++) {
        if (ncap->value[i]->name->nchars == nchars &&
            strncmp(ncap->value[i]->name->cp, name, nchars) == 0) {
            free(name);
            return i;
        }
    }
    free(name);

    return -1;
}

If this routine takes the early exit "none created yet", then "name" will not be freed causing a memory leak.  The "if(ncap->ndefined==0) return -1" line should be moved before the line that allocates "name"

This is parallel-netcdf-1.6.1
..Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/parallel-netcdf/attachments/20150714/fc188e52/attachment.html>


More information about the parallel-netcdf mailing list