#68 wrudf-cmnd.c: resource leak

open
nobody
None
5
2009-10-21
2009-10-21
dcb
No

For source code file udftools-1.0.0b3/wrudf/wrudf-cmnd.c
function copyFile

I notice the following code

fd = open(inName, O_RDONLY);
if( fd == 0 ) {
printf("'%s' does not exist\n", cmndv[i]);
return CMND_FAILED;
}

printf("Copy file %s\n", inName);
fid = findFileIdentDesc(dir, newName);

if( fid && questionOverwrite(dir, fid, newName) )
return CMND_OK;

so if the second return is taken, then fd is a resource leak.
Suggest new code

fd = open(inName, O_RDONLY);
if( fd == 0 ) {
printf("'%s' does not exist\n", cmndv[i]);
return CMND_FAILED;
}

printf("Copy file %s\n", inName);
fid = findFileIdentDesc(dir, newName);

if( fid && questionOverwrite(dir, fid, newName) )
{
close( fd);
return CMND_OK;
}

Discussion