Skip to content
Snippets Groups Projects
Commit 158ba873 authored by Daniel P. Berrangé's avatar Daniel P. Berrangé :speech_balloon:
Browse files

Merge all returns paths from dispatcher into single path

The dispatcher functions have numerous places where they
return to the caller. This leads to duplicated cleanup
code, often resulting in memory leaks. It makes it harder
to ensure that errors are dispatched before freeing objects,
which may overwrite the original error.

The standard pattern is now

    remoteDispatchXXX(...) {
        int rv = -1;

        ....
        if (XXX < 0)
          goto cleanup;
        ...
        if (XXXX < 0)
          goto cleanup;
        ...

        rv = 0;
    cleanup:
        if (rv < 0)
           remoteDispatchError(rerr);
        ...free all other stuff..
        return rv;
    }

* daemon/remote.c: Centralize all cleanup paths
* daemon/stream.c: s/remoteDispatchConnError/remoteDispatchError/
* daemon/dispatch.c, daemon/dispatch.h: Replace
  remoteDispatchConnError with remoteDispatchError
  removing unused virConnectPtr
parent 16d6b0d8
No related branches found
No related tags found
No related merge requests found
......@@ -112,8 +112,7 @@ void remoteDispatchOOMError (remote_error *rerr)
}
void remoteDispatchConnError (remote_error *rerr,
virConnectPtr conn ATTRIBUTE_UNUSED)
void remoteDispatchError(remote_error *rerr)
{
virErrorPtr verr = virGetLastError();
......
......@@ -46,8 +46,7 @@ void remoteDispatchFormatError (remote_error *rerr,
void remoteDispatchAuthError (remote_error *rerr);
void remoteDispatchGenericError (remote_error *rerr);
void remoteDispatchOOMError (remote_error *rerr);
void remoteDispatchConnError (remote_error *rerr,
virConnectPtr conn);
void remoteDispatchError(remote_error *rerr);
int
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -403,7 +403,7 @@ remoteStreamHandleWriteData(struct qemud_client *client,
} else {
VIR_INFO0("Stream send failed");
stream->closed = 1;
remoteDispatchConnError(&rerr, client->conn);
remoteDispatchError(&rerr);
return remoteSerializeReplyError(client, &rerr, &msg->hdr);
}
......@@ -437,7 +437,7 @@ remoteStreamHandleFinish(struct qemud_client *client,
ret = virStreamFinish(stream->st);
if (ret < 0) {
remoteDispatchConnError(&rerr, client->conn);
remoteDispatchError(&rerr);
return remoteSerializeReplyError(client, &rerr, &msg->hdr);
} else {
/* Send zero-length confirm */
......@@ -569,7 +569,7 @@ remoteStreamHandleRead(struct qemud_client *client,
} else if (ret < 0) {
remote_error rerr;
memset(&rerr, 0, sizeof rerr);
remoteDispatchConnError(&rerr, NULL);
remoteDispatchError(&rerr);
ret = remoteSerializeStreamError(client, &rerr, stream->procedure, stream->serial);
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment