qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] migration/dirtyrate: check malloc() return


From: Richard Henderson
Subject: Re: [RFC] migration/dirtyrate: check malloc() return
Date: Sat, 9 Apr 2022 23:00:01 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0

On 4/9/22 20:58, jianchunfu wrote:
Handling potential memory allocation failures in dirtyrate.

Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
---
  migration/dirtyrate.c | 8 ++++++++
  1 file changed, 8 insertions(+)

diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
index aace12a787..5dd40f32c8 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -523,9 +523,17 @@ static void calculate_dirtyrate_dirty_ring(struct 
DirtyRateConfig config)
      }
dirty_pages = malloc(sizeof(*dirty_pages) * nvcpu);
+    if (!dirty_pages) {
+        error_report("malloc dirty pages for vcpus failed.");
+        exit(1);
+    }
DirtyStat.dirty_ring.nvcpu = nvcpu;
      DirtyStat.dirty_ring.rates = malloc(sizeof(DirtyRateVcpu) * nvcpu);
+    if (!DirtyStat.dirty_ring.rates) {
+        error_report("malloc dirty rates for vcpu ring failed.");
+        exit(1);
+    }

You might as well use g_new(), which handles the sizeof and multiplication, and error reporting.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]