提交 6bf30786 编写于 作者: D Daniel P. Berrange

Fix leak of iterators in virDBusMessageIterEncode

If virDBusMessageIterEncode hits an OOM condition it often
leaks the memory associated with the dbus iterator object
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 1bf1b387
...@@ -601,8 +601,10 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, ...@@ -601,8 +601,10 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter,
goto cleanup; goto cleanup;
if (virDBusTypeStackPush(&stack, &nstack, if (virDBusTypeStackPush(&stack, &nstack,
iter, types, iter, types,
nstruct, narray) < 0) nstruct, narray) < 0) {
VIR_FREE(newiter);
goto cleanup; goto cleanup;
}
VIR_FREE(contsig); VIR_FREE(contsig);
iter = newiter; iter = newiter;
newiter = NULL; newiter = NULL;
...@@ -625,8 +627,10 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, ...@@ -625,8 +627,10 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter,
goto cleanup; goto cleanup;
if (virDBusTypeStackPush(&stack, &nstack, if (virDBusTypeStackPush(&stack, &nstack,
iter, types, iter, types,
nstruct, narray) < 0) nstruct, narray) < 0) {
VIR_FREE(newiter);
goto cleanup; goto cleanup;
}
iter = newiter; iter = newiter;
newiter = NULL; newiter = NULL;
types = vsig; types = vsig;
...@@ -657,8 +661,10 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, ...@@ -657,8 +661,10 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter,
if (virDBusTypeStackPush(&stack, &nstack, if (virDBusTypeStackPush(&stack, &nstack,
iter, types, iter, types,
nstruct, narray) < 0) nstruct, narray) < 0) {
VIR_FREE(newiter);
goto cleanup; goto cleanup;
}
VIR_FREE(contsig); VIR_FREE(contsig);
iter = newiter; iter = newiter;
newiter = NULL; newiter = NULL;
...@@ -678,6 +684,17 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, ...@@ -678,6 +684,17 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter,
ret = 0; ret = 0;
cleanup: cleanup:
while (nstack > 0) {
DBusMessageIter *thisiter = iter;
VIR_DEBUG("Popping iter=%p", iter);
ignore_value(virDBusTypeStackPop(&stack, &nstack, &iter,
&types, &nstruct, &narray));
VIR_DEBUG("Popped iter=%p", iter);
if (thisiter != rootiter)
VIR_FREE(thisiter);
}
virDBusTypeStackFree(&stack, &nstack); virDBusTypeStackFree(&stack, &nstack);
VIR_FREE(contsig); VIR_FREE(contsig);
VIR_FREE(newiter); VIR_FREE(newiter);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册