Browse Source

tools: Remove fd leak

compile_info() can leak an open file descriptor write_all() fails.  This
corrects it.

Found by Coverity.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson 8 years ago
parent
commit
fb8e88fce3
1 changed files with 3 additions and 1 deletions
  1. 3 1
      tools/depends.c

+ 3 - 1
tools/depends.c

@@ -54,8 +54,10 @@ char *compile_info(const void *ctx, const char *dir)
 	fd = open(info_c_file, O_WRONLY|O_CREAT|O_EXCL, 0600);
 	fd = open(info_c_file, O_WRONLY|O_CREAT|O_EXCL, 0600);
 	if (fd < 0)
 	if (fd < 0)
 		return NULL;
 		return NULL;
-	if (!write_all(fd, info, tal_count(info)-1))
+	if (!write_all(fd, info, tal_count(info)-1)) {
+		close(fd);
 		return NULL;
 		return NULL;
+	}
 
 
 	if (close(fd) != 0)
 	if (close(fd) != 0)
 		return NULL;
 		return NULL;