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 <jtomko@xxxxxxxxxx> --- 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 0b2ae59910..91575f4d34 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"; -- 2.26.2