vvfat: avoid leaking file descriptor in commit_one_file()

Reported-by: Dr David Alan Gilbert <davidagilbert@uk.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
This commit is contained in:
Stefan Hajnoczi 2012-01-06 16:57:44 +00:00
parent dabdf39425
commit 8d98734651

View File

@ -2218,6 +2218,7 @@ static int commit_one_file(BDRVVVFATState* s,
} }
if (offset > 0) { if (offset > 0) {
if (lseek(fd, offset, SEEK_SET) != offset) { if (lseek(fd, offset, SEEK_SET) != offset) {
close(fd);
g_free(cluster); g_free(cluster);
return -3; return -3;
} }
@ -2238,11 +2239,13 @@ static int commit_one_file(BDRVVVFATState* s,
(uint8_t*)cluster, (rest_size + 0x1ff) / 0x200); (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
if (ret < 0) { if (ret < 0) {
close(fd);
g_free(cluster); g_free(cluster);
return ret; return ret;
} }
if (write(fd, cluster, rest_size) < 0) { if (write(fd, cluster, rest_size) < 0) {
close(fd);
g_free(cluster); g_free(cluster);
return -2; return -2;
} }