[PATCH] rpc: Fix memory leak in remoteDomainSet*Parameters functions

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

 



Add a new helper remoteFreeTypedParameters and teach the generator
to add it to the cleanup section.

https://bugzilla.redhat.com/show_bug.cgi?id=725322
---
 src/remote/remote_driver.c |   22 +++++++++++++++++-----
 src/rpc/gendispatch.pl     |    5 +++++
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 0652e0d..e5bfa4b 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1208,6 +1208,22 @@ done:
     return rv;
 }
 
+/* Helper to free typed parameters. */
+static void
+remoteFreeTypedParameters(remote_typed_param *args_params_val,
+                          u_int args_params_len)
+{
+    u_int i;
+
+    if (args_params_val == NULL)
+        return;
+
+    for (i = 0; i < args_params_len; i++)
+        VIR_FREE(args_params_val[i].field);
+
+    VIR_FREE(args_params_val);
+}
+
 /* Helper to serialize typed parameters. */
 static int
 remoteSerializeTypedParameters(virTypedParameterPtr params,
@@ -1264,11 +1280,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params,
     rv = 0;
 
 cleanup:
-    if (val) {
-        for (i = 0; i < nparams; i++)
-            VIR_FREE(val[i].field);
-        VIR_FREE(val);
-    }
+    remoteFreeTypedParameters(val, nparams);
     return rv;
 }
 
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index ceeb1f5..0d344e8 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -979,6 +979,7 @@ elsif ($opt_k) {
         my @args_check_list = ();
         my @setters_list = ();
         my @setters_list2 = ();
+        my @free_list = ();
         my $priv_src = "conn";
         my $priv_name = "privateData";
         my $call_args = "&args";
@@ -1105,6 +1106,7 @@ elsif ($opt_k) {
                                          "        xdr_free((xdrproc_t)xdr_$call->{args}, (char *)&args);\n" .
                                          "        goto done;\n" .
                                          "    }");
+                    push(@free_list, "    remoteFreeTypedParameters(args.params.params_val, args.params.params_len);\n");
                 } elsif ($args_member =~ m/^((?:unsigned )?int) (\S+);\s*\/\*\s*call-by-reference\s*\*\//) {
                     my $type_name = "$1 *";
                     my $arg_name = $2;
@@ -1500,6 +1502,9 @@ elsif ($opt_k) {
 
         print "\n";
         print "done:\n";
+
+        print join("\n", @free_list);
+
         print "    remoteDriverUnlock(priv);\n";
         print "    return rv;\n";
         print "}\n";
-- 
1.7.4.1

--
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]