From 99c709765a1bdd34f456280d68051e7f9177a13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 30 Sep 2020 15:40:06 +0200 Subject: [PATCH] gendispatch: use g_new0 instead of VIR_ALLOC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Take the easy way out and use typeof, because my life is too short to spend it reading gendispatch.pl. Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- src/rpc/gendispatch.pl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 590a46ef66..0020273d9e 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -797,8 +797,7 @@ elsif ($mode eq "server") { push(@free_list, " VIR_FREE($1);"); push(@free_list_on_error, "VIR_FREE($1_p);"); push(@prepare_ret_list, - "if (VIR_ALLOC($1_p) < 0)\n" . - " goto cleanup;\n" . + "$1_p = g_new0(char *, 1);\n" . "\n" . " *$1_p = g_strdup($1);\n"); @@ -1126,9 +1125,9 @@ elsif ($mode eq "server") { if ($single_ret_as_list) { print " /* Allocate return buffer. */\n"; - print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${single_ret_list_name}_val," . - " args->$single_ret_list_max_var) < 0)\n"; - print " goto cleanup;\n"; + print " ret->$single_ret_list_name.${single_ret_list_name}_val =\n"; + print " g_new0(typeof(*ret->$single_ret_list_name.${single_ret_list_name}_val), " . + "args->$single_ret_list_max_var);\n"; print "\n"; } @@ -1188,8 +1187,8 @@ elsif ($mode eq "server") { print " }\n"; print "\n"; print " if (result && nresults) {\n"; - print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${single_ret_list_name}_val, nresults) < 0)\n"; - print " goto cleanup;\n"; + print " ret->$single_ret_list_name.${single_ret_list_name}_val =\n"; + print " g_new0(typeof(*ret->$single_ret_list_name.${single_ret_list_name}_val), nresults);\n"; print "\n"; print " ret->$single_ret_list_name.${single_ret_list_name}_len = nresults;\n"; if ($modern_ret_is_nested) { @@ -1950,8 +1949,7 @@ elsif ($mode eq "client") { $priv_src =~ s/->conn//; } print " if (result) {\n"; - print " if (VIR_ALLOC_N(tmp_results, ret.$single_ret_list_name.${single_ret_list_name}_len + 1) < 0)\n"; - print " goto cleanup;\n"; + print " tmp_results = g_new0(typeof(*tmp_results), ret.$single_ret_list_name.${single_ret_list_name}_len + 1);\n"; print "\n"; print " for (i = 0; i < ret.$single_ret_list_name.${single_ret_list_name}_len; i++) {\n"; print " tmp_results[i] = get_nonnull_$modern_ret_struct_name($priv_src, ret.$single_ret_list_name.${single_ret_list_name}_val[i]);\n";