libs/devicemodel: free xencall handle in error path in _open()
authorWei Liu <wei.liu2@citrix.com>
Mon, 27 Feb 2017 12:20:26 +0000 (12:20 +0000)
committerWei Liu <wei.liu2@citrix.com>
Mon, 27 Feb 2017 16:33:56 +0000 (16:33 +0000)
Change the allocation to use calloc to get zeroed structure. Free
xencall handler in error path.

Spotted by Coverity.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libs/devicemodel/core.c

index 19ebef63b3b51fd9c8c3858cf7d29c26f9fefae6..a85cb49c22df2a9cddf4ff70754cff6f36dbfdec 100644 (file)
@@ -24,7 +24,7 @@
 xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger,
                                            unsigned open_flags)
 {
-    xendevicemodel_handle *dmod = malloc(sizeof(*dmod));
+    xendevicemodel_handle *dmod = calloc(1, sizeof(*dmod));
     int rc;
 
     if (!dmod)
@@ -54,6 +54,7 @@ xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger,
 
 err:
     xtl_logger_destroy(dmod->logger_tofree);
+    xencall_close(dmod->xcall);
     free(dmod);
     return NULL;
 }