pud: fix resource leak
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 22 Oct 2012 09:48:21 +0000 (11:48 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 22 Oct 2012 11:55:38 +0000 (13:55 +0200)
Coverity:
CID 739679 (#1 of 1): Resource leak (RESOURCE_LEAK)
At (24): Variable "fd" going out of scope leaks the storage it points to.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/posFile.c

index 12e0987..42d5878 100644 (file)
@@ -282,6 +282,7 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
        }
 
        fclose(fd);
+       fd = 0;
 
        result.smask = POSFILE_DEFAULT_SMASK;
        nmea_INFO_set_present(&result.present, SMASK);
@@ -292,5 +293,8 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
        memcpy(nmeaInfo, &result, sizeof(result));
        retval = true;
 
-       out: return retval;
+       out: if (fd) {
+               fclose(fd);
+       }
+       return retval;
 }