aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Compostella <jeremy.compostella@intel.com>2015-09-08 19:15:09 +0200
committerSteve Kondik <steve@cyngn.com>2015-11-07 19:21:20 -0800
commitb810ee75a15f0267236873e0c66a2279dee7c737 (patch)
tree5bf03ae462a6bfc750ab12d692814394986f9a19
parent568d2b60266bf1583e57bb27ba5f23b3d8777c4e (diff)
downloadbootable_recovery-b810ee75a15f0267236873e0c66a2279dee7c737.zip
bootable_recovery-b810ee75a15f0267236873e0c66a2279dee7c737.tar.gz
bootable_recovery-b810ee75a15f0267236873e0c66a2279dee7c737.tar.bz2
imgdiff: fix file descriptor leak
mkstemp() allocates a file description that is never released. If MakePatch() is called too many time, imgdiff reaches the Operating System EMFILE (too many open files) limit. Change-Id: Icbe1399f6f6d32cfa1830f879cacf7d75bbd9fc3 Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com> Signed-off-by: Gaelle Nassiet <gaellex.nassiet@intel.com>
-rw-r--r--applypatch/imgdiff.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/applypatch/imgdiff.c b/applypatch/imgdiff.c
index 3bac8be..e12a385 100644
--- a/applypatch/imgdiff.c
+++ b/applypatch/imgdiff.c
@@ -623,7 +623,15 @@ unsigned char* MakePatch(ImageChunk* src, ImageChunk* tgt, size_t* size) {
}
char ptemp[] = "/tmp/imgdiff-patch-XXXXXX";
- mkstemp(ptemp);
+ int fd = mkstemp(ptemp);
+
+ if (fd == -1) {
+ printf("MakePatch failed to create a temporary file: %s\n",
+ strerror(errno));
+ return NULL;
+ }
+ close(fd); // temporary file is created and we don't need its file
+ // descriptor
int r = bsdiff(src->data, src->len, &(src->I), tgt->data, tgt->len, ptemp);
if (r != 0) {