提交 6fc85042 编写于 作者: P Peter Krempa

remote: Use g_new0 to allocate 'remote_string' in event RPC handlers

Few events emit optional strings. We need to allocate the container for
it first. Note that remote_nonnull_string is used as the type as the
internal part of the string is nonnull if the container is present.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
ACKed-by: NEric Blake <eblake@redhat.com>
上级 d89544f6
...@@ -722,14 +722,12 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, ...@@ -722,14 +722,12 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn,
/* build return data */ /* build return data */
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
if (oldSrcPath) { if (oldSrcPath) {
if (VIR_ALLOC(data.oldSrcPath) < 0) data.oldSrcPath = g_new0(remote_nonnull_string, 1);
goto error;
*(data.oldSrcPath) = g_strdup(oldSrcPath); *(data.oldSrcPath) = g_strdup(oldSrcPath);
} }
if (newSrcPath) { if (newSrcPath) {
if (VIR_ALLOC(data.newSrcPath) < 0) data.newSrcPath = g_new0(remote_nonnull_string, 1);
goto error;
*(data.newSrcPath) = g_strdup(newSrcPath); *(data.newSrcPath) = g_strdup(newSrcPath);
} }
...@@ -751,11 +749,6 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, ...@@ -751,11 +749,6 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn,
} }
return 0; return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_disk_change_msg,
(char *) &data);
return -1;
} }
...@@ -1263,8 +1256,7 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn, ...@@ -1263,8 +1256,7 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn,
data.type = type; data.type = type;
if (nsuri) { if (nsuri) {
if (VIR_ALLOC(data.nsuri) < 0) data.nsuri = g_new0(remote_nonnull_string, 1);
goto error;
*(data.nsuri) = g_strdup(nsuri); *(data.nsuri) = g_strdup(nsuri);
} }
...@@ -1277,11 +1269,6 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn, ...@@ -1277,11 +1269,6 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn,
&data); &data);
return 0; return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_callback_metadata_change_msg,
(char *) &data);
return -1;
} }
...@@ -1309,8 +1296,7 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn, ...@@ -1309,8 +1296,7 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn,
data.callbackID = callback->callbackID; data.callbackID = callback->callbackID;
data.dev = g_strdup(dev); data.dev = g_strdup(dev);
if (path) { if (path) {
if (VIR_ALLOC(data.path) < 0) data.path = g_new0(remote_nonnull_string, 1);
goto error;
*(data.path) = g_strdup(path); *(data.path) = g_strdup(path);
} }
data.threshold = threshold; data.threshold = threshold;
...@@ -1322,11 +1308,6 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn, ...@@ -1322,11 +1308,6 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn,
(xdrproc_t)xdr_remote_domain_event_block_threshold_msg, &data); (xdrproc_t)xdr_remote_domain_event_block_threshold_msg, &data);
return 0; return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_block_threshold_msg,
(char *) &data);
return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册