Re: [PATCH] tests: Fix memory leak in virnetmessagetest

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

 



于 2011年06月28日 21:10, Eric Blake 写道:
On 06/28/2011 03:16 AM, Osier Yang wrote:
Detected when playing with "make -C tests valgrind".
---
  tests/virnetmessagetest.c |   35 ++++++++++++++++++++++++-----------
  1 files changed, 24 insertions(+), 11 deletions(-)


      if (VIR_ALLOC(err.str3)<  0)
-        return -1;
+        goto cleanup;
      *err.str3 = strdup("Three");

+cleanup:
+    VIR_FREE(*err.message);
+    VIR_FREE(*err.str1);
+    VIR_FREE(*err.str2);
+    VIR_FREE(*err.str3);

Ouch - four potential NULL derefs.  You need to write these as:

if (err.str3)
     VIR_FREE(*err.str3);

and so forth.

ah, yes


+    VIR_FREE(err.message);
+    VIR_FREE(err.str1);
+    VIR_FREE(err.str2);
+    VIR_FREE(err.str3);

But these four are okay.

+    return ret;

ACK with that fix.


Applied with the fix, thanks

Osier

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]