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

Wei-keng Liao wkliao at eecs.northwestern.edu
Tue Jul 14 11:43:07 CDT 2015


Hi, Greg

Thanks for pointing this out.
I will add the fix you suggested.

Wei-keng

On Jul 14, 2015, at 11:11 AM, Sjaardema, Gregory D wrote:

> 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



More information about the parallel-netcdf mailing list