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

Re: [libvirt] [PATCHv4] network: Avoid memory leaks on networkBuildDnsmasqArgv



On 02/01/2012 02:22 AM, ajia redhat com wrote:
> From: Alex Jia <ajia redhat com>
> 
> Detected by valgrind. Leaks introduced in commit 973af236.
> 
> * src/network/bridge_driver.c: fix memory leaks on failure and successful path.
> 
> * How to reproduce?
> % make -C tests check TESTS=networkxml2argvtest
> % cd tests && valgrind -v --leak-check=full ./networkxml2argvtest
> 

> 
> Signed-off-by: Alex Jia <ajia redhat com>
> ---
>  src/network/bridge_driver.c |   17 +++++++++++------
>  1 files changed, 11 insertions(+), 6 deletions(-)
> 

> @@ -516,7 +520,6 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
>          int i;
>  
>          for (i = 0; i < dns->ntxtrecords; i++) {
> -            char *record = NULL;
>              if (virAsprintf(&record, "%s,%s",
>                              dns->txtrecords[i].name,
>                              dns->txtrecords[i].value) < 0) {

Hmm, we can simplify this loop even further, by using the right function
in the first place.

ACK to what you had, and I'm squashing this in then pushing:

diff --git i/src/network/bridge_driver.c w/src/network/bridge_driver.c
index fb06b64..220f99e 100644
--- i/src/network/bridge_driver.c
+++ w/src/network/bridge_driver.c
@@ -520,15 +520,10 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
         int i;

         for (i = 0; i < dns->ntxtrecords; i++) {
-            if (virAsprintf(&record, "%s,%s",
-                            dns->txtrecords[i].name,
-                            dns->txtrecords[i].value) < 0) {
-                virReportOOMError();
-                goto cleanup;
-            }
-
-            virCommandAddArgPair(cmd, "--txt-record", record);
-            VIR_FREE(record);
+            virCommandAddArg(cmd, "--txt-record");
+            virCommandAddArgFormat(cmd, "%s,%s",
+                                   dns->txtrecords[i].name,
+                                   dns->txtrecords[i].value);
         }

         for (i = 0; i < dns->nsrvrecords; i++) {


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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