[PATCH master 3/3] sandbox: fix use of initialized variable in error path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



fd could be uninitialized in some error paths. Give it a value that
close can be called on without adverse effect.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 arch/sandbox/os/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index fd75cc04cc16..d09604af1400 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -321,7 +321,7 @@ int linux_open_hostfile(struct hf_info *hf)
 {
 	char *buf = NULL;
 	struct stat s;
-	int fd;
+	int fd = -1;
 
 	printf("add %s %sbacked by file %s%s\n", hf->devname,
 	       hf->filename ? "" : "initially un", hf->filename ?: "",
@@ -408,7 +408,7 @@ int linux_open_hostfile(struct hf_info *hf)
 	return 0;
 
 err_out:
-	if (fd > 0)
+	if (fd >= 0)
 		close(fd);
 	free(buf);
 	return -1;
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux