提交 8d987346 编写于 作者: S Stefan Hajnoczi

vvfat: avoid leaking file descriptor in commit_one_file()

Reported-by: NDr David Alan Gilbert <davidagilbert@uk.ibm.com>
Signed-off-by: NStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
上级 dabdf394
...@@ -2218,6 +2218,7 @@ static int commit_one_file(BDRVVVFATState* s, ...@@ -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, ...@@ -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;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册