remote: check & report OOM in make_nonnull_XXX methods

The make_nonnull_XXX methods can all fail due to OOM but this was being
silently ignored and thus also not checked by callers. Make the methods
propagate errors and use ATTRIBUTE_RETURN_CHECK to force callers to deal
with it.
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 60046283
...@@ -113,11 +113,13 @@ get_nonnull_server(virNetDaemonPtr dmn, admin_nonnull_server srv) ...@@ -113,11 +113,13 @@ get_nonnull_server(virNetDaemonPtr dmn, admin_nonnull_server srv)
return virNetDaemonGetServer(dmn, srv.name); return virNetDaemonGetServer(dmn, srv.name);
} }
static void static int ATTRIBUTE_RETURN_CHECK
make_nonnull_server(admin_nonnull_server *srv_dst, make_nonnull_server(admin_nonnull_server *srv_dst,
virNetServerPtr srv_src) virNetServerPtr srv_src)
{ {
ignore_value(VIR_STRDUP_QUIET(srv_dst->name, virNetServerGetName(srv_src))); if (VIR_STRDUP(srv_dst->name, virNetServerGetName(srv_src)) < 0)
return -1;
return 0;
} }
static virNetServerClientPtr static virNetServerClientPtr
...@@ -126,13 +128,14 @@ get_nonnull_client(virNetServerPtr srv, admin_nonnull_client clnt) ...@@ -126,13 +128,14 @@ get_nonnull_client(virNetServerPtr srv, admin_nonnull_client clnt)
return virNetServerGetClient(srv, clnt.id); return virNetServerGetClient(srv, clnt.id);
} }
static void static int
make_nonnull_client(admin_nonnull_client *clt_dst, make_nonnull_client(admin_nonnull_client *clt_dst,
virNetServerClientPtr clt_src) virNetServerClientPtr clt_src)
{ {
clt_dst->id = virNetServerClientGetID(clt_src); clt_dst->id = virNetServerClientGetID(clt_src);
clt_dst->timestamp = virNetServerClientGetTimestamp(clt_src); clt_dst->timestamp = virNetServerClientGetTimestamp(clt_src);
clt_dst->transport = virNetServerClientGetTransport(clt_src); clt_dst->transport = virNetServerClientGetTransport(clt_src);
return 0;
} }
/* Functions */ /* Functions */
......
此差异已折叠。
...@@ -786,12 +786,12 @@ elsif ($mode eq "server") { ...@@ -786,12 +786,12 @@ elsif ($mode eq "server") {
if ($call->{ProcName} eq "DomainCreateWithFlags") { if ($call->{ProcName} eq "DomainCreateWithFlags") {
# SPECIAL: virDomainCreateWithFlags updates the given # SPECIAL: virDomainCreateWithFlags updates the given
# domain object instead of returning a new one # domain object instead of returning a new one
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);"); push(@ret_list, "if (make_nonnull_$1(&ret->$2, $2) < 0)\n goto cleanup;\n");
$single_ret_var = undef; $single_ret_var = undef;
$single_ret_by_ref = 1; $single_ret_by_ref = 1;
} else { } else {
push(@vars_list, "vir${type_name}Ptr $2 = NULL"); push(@vars_list, "vir${type_name}Ptr $2 = NULL");
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);"); push(@ret_list, "if (make_nonnull_$1(&ret->$2, $2) < 0)\n goto cleanup;\n");
push(@free_list, push(@free_list,
" virObjectUnref($2);"); " virObjectUnref($2);");
$single_ret_var = $2; $single_ret_var = $2;
...@@ -907,11 +907,11 @@ elsif ($mode eq "server") { ...@@ -907,11 +907,11 @@ elsif ($mode eq "server") {
if ($1 eq "client") { if ($1 eq "client") {
push(@vars_list, "virNetServer${type_name}Ptr $2 = NULL"); push(@vars_list, "virNetServer${type_name}Ptr $2 = NULL");
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);"); push(@ret_list, "if (make_nonnull_$1(&ret->$2, $2) < 0)\n goto cleanup;\n");
push(@ret_list, "make_nonnull_server(&ret->$2.srv, srv);"); push(@ret_list, "if (make_nonnull_server(&ret->$2.srv, srv) < 0)\n goto cleanup;\n");
} else { } else {
push(@vars_list, "virNet${type_name}Ptr $2 = NULL"); push(@vars_list, "virNet${type_name}Ptr $2 = NULL");
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);"); push(@ret_list, "if (make_nonnull_$1(&ret->$2, $2) < 0)\n goto cleanup;\n");
} }
push(@free_list, push(@free_list,
...@@ -1175,12 +1175,15 @@ elsif ($mode eq "server") { ...@@ -1175,12 +1175,15 @@ elsif ($mode eq "server") {
print " ret->$single_ret_list_name.${single_ret_list_name}_len = nresults;\n"; print " ret->$single_ret_list_name.${single_ret_list_name}_len = nresults;\n";
if ($modern_ret_is_nested) { if ($modern_ret_is_nested) {
print " for (i = 0; i < nresults; i++) {\n"; print " for (i = 0; i < nresults; i++) {\n";
print " make_nonnull_$modern_ret_struct_name(ret->$single_ret_list_name.${single_ret_list_name}_val + i, result[i]);\n"; print " if (make_nonnull_$modern_ret_struct_name(ret->$single_ret_list_name.${single_ret_list_name}_val + i, result[i]) < 0)\n";
print " make_nonnull_$modern_ret_nested_struct_name(&ret->$single_ret_list_name.${single_ret_list_name}_val[i].srv, srv);\n"; print " goto cleanup;\n";
print " if (make_nonnull_$modern_ret_nested_struct_name(&ret->$single_ret_list_name.${single_ret_list_name}_val[i].srv, srv) < 0)\n";
print " goto cleanup;\n";
print " }\n"; print " }\n";
} else { } else {
print " for (i = 0; i < nresults; i++)\n"; print " for (i = 0; i < nresults; i++)\n";
print " make_nonnull_$modern_ret_struct_name(ret->$single_ret_list_name.${single_ret_list_name}_val + i, result[i]);\n"; print " if (make_nonnull_$modern_ret_struct_name(ret->$single_ret_list_name.${single_ret_list_name}_val + i, result[i]) < 0)\n";
print " goto cleanup;\n";
} }
print " } else {\n"; print " } else {\n";
print " ret->$single_ret_list_name.${single_ret_list_name}_len = 0;\n"; print " ret->$single_ret_list_name.${single_ret_list_name}_len = 0;\n";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部