From: Andrea Bolognani Date: Wed, 5 Apr 2017 16:24:33 +0000 (+0200) Subject: storage: Avoid leak in virStorageUtilGlusterExtractPoolSources() X-Git-Tag: v3.3.0-rc1~270 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=611ddefc1666459688bfe68e79f2ddc07d417831;p=thirdparty%2Flibvirt.git storage: Avoid leak in virStorageUtilGlusterExtractPoolSources() The contents of volname would be leaked if the function were to be passed an invalid pooltype by the caller. Make sure the memory is released instead. --- diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7cc125a384..8e25984d75 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2846,7 +2846,7 @@ virStorageUtilGlusterExtractPoolSources(const char *host, xmlXPathContextPtr ctxt = NULL; xmlNodePtr *nodes = NULL; virStoragePoolSource *src = NULL; - char *volname; + char *volname = NULL; size_t i; int nnodes; int ret = -1; @@ -2871,12 +2871,11 @@ virStorageUtilGlusterExtractPoolSources(const char *host, if (pooltype == VIR_STORAGE_POOL_NETFS) { src->format = VIR_STORAGE_POOL_NETFS_GLUSTERFS; - src->dir = volname; + VIR_STEAL_PTR(src->dir, volname); } else if (pooltype == VIR_STORAGE_POOL_GLUSTER) { - src->name = volname; - if (VIR_STRDUP(src->dir, "/") < 0) goto cleanup; + VIR_STEAL_PTR(src->name, volname); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unsupported gluster lookup")); @@ -2894,6 +2893,7 @@ virStorageUtilGlusterExtractPoolSources(const char *host, ret = nnodes; cleanup: + VIR_FREE(volname); VIR_FREE(nodes); xmlXPathFreeContext(ctxt); xmlFreeDoc(doc);