rpc: Fix memory leak in remoteDomainSet*Parameters functions

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
This commit is contained in:
Matthias Bolte 2011-07-27 20:32:25 +02:00
parent 4ab0260956
commit 8d2319cb90
2 changed files with 22 additions and 5 deletions

View File

@ -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;
}

View File

@ -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";