Skip to contentSkip to conversation

kvm: fix memory leak on failure to read stats descriptors

PATCH Superseded Paolo Bonzini 3 participants 3 messages Sep 5, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: fix memory leak on failure to read stats descriptors

Reported by Coverity as CID 1490142.

---
 accel/kvm/kvm-all.c | 1 +
 1 file changed, 1 insertion(+)
accel/kvm/kvm-all.c +1 -0
index 7c8ce18bdd..208b0c74e3 100644
@@ -3962,6 +3962,7 @@ static StatsDescriptors *find_stats_descriptors(StatsTarget target, int stats_fd
                    size_desc * kvm_stats_header->num_desc, ret);
         g_free(descriptors);
         g_free(kvm_stats_desc);
+        g_free(kvm_stats_header);
         return NULL;
     }
     descriptors->kvm_stats_header = kvm_stats_header;
Signature · 1 line
2.37.2
#1 lore raw
Quoted 12 lines · Paolo Bonzini

Reported by Coverity as CID 1490142.

---
  accel/kvm/kvm-all.c | 1 +
  1 file changed, 1 insertion(+)
accel/kvm/kvm-all.c +0 -0
index 7c8ce18bdd..208b0c74e3 100644

accel/kvm/kvm-all.c static StatsDescriptors *find_stats_descriptors(StatsTarget target, int stats_fd · line 3967

Quoted 6 lines
accel/kvm/kvm-all.c +1 -0
@@ -3962,6 +3962,7 @@ static StatsDescriptors *find_stats_descriptors(StatsTarget target, int stats_fd
                     size_desc * kvm_stats_header->num_desc, ret);
          g_free(descriptors);
          g_free(kvm_stats_desc);
+        g_free(kvm_stats_header);
          return NULL;
      }

kvm_stats_header should also be freed just above, in the other read failure if block.

Alternately, can StatsDescriptors be reorg'ed as

  typedef struct StatsDescriptors {

const char *ident; /* cache key, currently the StatsTarget */

struct kvm_stats_desc *kvm_stats_desc;

- struct kvm_stats_header *kvm_stats_header;

+     struct kvm_stats_header kvm_stats_header;
      QTAILQ_ENTRY(StatsDescriptors) next;
  } StatsDescriptors;

since it appears that kvm_stats_header has the same lifetime as the descriptor, and is not variable sized, like kvm_stats_desc.

r~

Reviewed-by on v1 1/1
#2 lore raw
In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini

Reported by Coverity as CID 1490142.

Quoted 22 lines
---
 accel/kvm/kvm-all.c | 1 +
 1 file changed, 1 insertion(+)
accel/kvm/kvm-all.c +1 -0
index 7c8ce18bdd..208b0c74e3 100644
@@ -3962,6 +3962,7 @@ static StatsDescriptors
 *find_stats_descriptors(StatsTarget target, int stats_fd
                    size_desc * kvm_stats_header->num_desc, ret);
         g_free(descriptors);
         g_free(kvm_stats_desc);
+        g_free(kvm_stats_header);
         return NULL;
     }
     descriptors->kvm_stats_header = kvm_stats_header;

--
2.37.2

Signature · 1 line
Marc-André Lureau