[virt-tools-list] [vhostmd PATCH 05/18] libmetrics: Ensure libmetrics mutex is unlocked in error paths

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


>From coverity scan

vhostmd-1.1/libmetrics/libmetrics.c:595: missing_unlock: Returning without unlocking "libmetrics_mutex".
  593|          if (mdisk_alloc() == NULL) {
  594|              errno = ENOMEM;
  595|->            return -1;
  596|          }
  597|          read_mdisk(mdisk);

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

diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
index 2819f80..756645c 100644
--- a/libmetrics/libmetrics.c
+++ b/libmetrics/libmetrics.c
@@ -601,7 +601,7 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
        mdisk_free();
        if (mdisk_alloc() == NULL) {
            errno = ENOMEM;
-           return -1;
+           goto out;
        }
        read_mdisk(mdisk);
    }
@@ -620,7 +620,7 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
    
       if ((lmdef = metric_alloc_padded(extra_len)) == NULL) {
          errno = ENOMEM;
-         return -1;
+         goto out;
       }
 
       lmdef->type = pmdef.type;
@@ -635,6 +635,7 @@ 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