[virt-tools-list] [vhostmd PATCH 06/18] libmetrics: Fix potential memory leak

Jim Fehlig jfehlig at suse.com
Wed Jan 15 22:07:42 UTC 2020


>From coverity scan

vhostmd-1.1/libmetrics/libmetrics.c:613:18: warning: Potential leak of memory pointed to by 'pmdef.context'
         errno = ENOMEM;

Signed-off-by: Jim Fehlig <jfehlig at suse.com>
---
 libmetrics/libmetrics.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
index 756645c..6817df9 100644
--- a/libmetrics/libmetrics.c
+++ b/libmetrics/libmetrics.c
@@ -586,7 +586,8 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
    int ret = -1;
 
    *mdef = NULL;
-
+   memset(&pmdef, 0, sizeof(private_metric));
+   
    if (mdisk == NULL) {
        errno = ENODEV;
        return -1;
@@ -628,6 +629,8 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
       *mdef = lmdef;
       ret = 0;
    }
+
+out:
    if (pmdef.name)
       free(pmdef.name);
    if (pmdef.value)
@@ -635,7 +638,6 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
    if (pmdef.context)
       free(pmdef.context);
 
-out:
    /* unlock library data */
    pthread_mutex_unlock(&libmetrics_mutex);
    return ret;
-- 
2.16.4





More information about the virt-tools-list mailing list