If fileDescriptor is not retrieved don't close it, and if firmwareFileSize is negative fail. CID 3493 CID CID 3494.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39976 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Fredrik Holmqvist 2010-12-28 12:34:16 +00:00
parent ec349ca3bb
commit 2a74e90028

View File

@ -47,7 +47,7 @@ const struct firmware*
firmware_get(const char* fbsdFirmwareName)
{
char* fbsdFirmwareNameCopy = NULL;
int fileDescriptor = 0;
int fileDescriptor = -1;
struct firmware* firmware = NULL;
int32 firmwareFileSize;
char* firmwarePath = NULL;
@ -75,6 +75,9 @@ firmware_get(const char* fbsdFirmwareName)
goto cleanup;
firmwareFileSize = lseek(fileDescriptor, 0, SEEK_END);
if (firmwareFileSize == -1)
goto cleanup;
lseek(fileDescriptor, 0, SEEK_SET);
fbsdFirmwareNameCopy = strndup(fbsdFirmwareName,
@ -111,7 +114,7 @@ cleanup:
free(fbsdFirmwareNameCopy);
if (firmwarePath)
free(firmwarePath);
if (fileDescriptor)
if (fileDescriptor >= 0)
close(fileDescriptor);
return NULL;
}