[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Resource leak and possible double-fclose



Jonathan Nieder wrote:
> Raphael Geissert wrote:
>> diff --git a/dpkg-deb/info.c b/dpkg-deb/info.c
>> index 9ce7e76..ca9c747 100644
>> --- a/dpkg-deb/info.c
>> +++ b/dpkg-deb/info.c
>> @@ -185,6 +185,8 @@ static void info_list(const char *debar, const char
>> *directory) {
>>        putc('\n', stdout);
>>    }
>>  
>> +  fclose(cc);
>> +
> 
> This seems dangerous: if the control file was missing, this will
> fclose(NULL), which might have bad behavior on some platforms.

Right, fclose returns NULL on failure.

> 
>> @@ -290,8 +290,7 @@ void writecurrentopt() {
>>    if (fprintf(cmo,"%s %s\n",coption->meth->name,coption->name) == EOF) {
>>      fclose(cmo);
>>      ohshite(_("unable to write new option to `%.250s'"),newfile);
>> -  }
>> -  if (fclose(cmo))
>> +  } else if (fclose(cmo))
> 
> Isn’t this unnecessary?  ohshite() cannot return.

Right, should have been more careful. This is a false positive.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net



Reply to: