emulator: fix potential resource leak
authorTedd Ho-Jeong An <tedd.an@intel.com>
Tue, 16 Nov 2021 06:49:49 +0000 (22:49 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:38 +0000 (19:08 +0530)
This patch releases the allocated fd to prevent the potential resource
leak. This was reported by the Coverity scan.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
emulator/vhci.c

index 59ad1ec..014df87 100755 (executable)
@@ -140,8 +140,10 @@ struct vhci *vhci_open(uint8_t type)
        }
 
        vhci = malloc(sizeof(*vhci));
-       if (!vhci)
+       if (!vhci) {
+               close(fd);
                return NULL;
+       }
 
        memset(vhci, 0, sizeof(*vhci));
        vhci->type = type;