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
This commit is contained in:
Daniel P. Berrange 2011-04-13 16:21:35 +01:00
parent 16d6b0d80a
commit 158ba8730e
4 changed files with 2926 additions and 1975 deletions

View File

@ -112,8 +112,7 @@ void remoteDispatchOOMError (remote_error *rerr)
} }
void remoteDispatchConnError (remote_error *rerr, void remoteDispatchError(remote_error *rerr)
virConnectPtr conn ATTRIBUTE_UNUSED)
{ {
virErrorPtr verr = virGetLastError(); virErrorPtr verr = virGetLastError();

View File

@ -46,8 +46,7 @@ void remoteDispatchFormatError (remote_error *rerr,
void remoteDispatchAuthError (remote_error *rerr); void remoteDispatchAuthError (remote_error *rerr);
void remoteDispatchGenericError (remote_error *rerr); void remoteDispatchGenericError (remote_error *rerr);
void remoteDispatchOOMError (remote_error *rerr); void remoteDispatchOOMError (remote_error *rerr);
void remoteDispatchConnError (remote_error *rerr, void remoteDispatchError(remote_error *rerr);
virConnectPtr conn);
int int

File diff suppressed because it is too large Load Diff

View File

@ -403,7 +403,7 @@ remoteStreamHandleWriteData(struct qemud_client *client,
} else { } else {
VIR_INFO0("Stream send failed"); VIR_INFO0("Stream send failed");
stream->closed = 1; stream->closed = 1;
remoteDispatchConnError(&rerr, client->conn); remoteDispatchError(&rerr);
return remoteSerializeReplyError(client, &rerr, &msg->hdr); return remoteSerializeReplyError(client, &rerr, &msg->hdr);
} }
@ -437,7 +437,7 @@ remoteStreamHandleFinish(struct qemud_client *client,
ret = virStreamFinish(stream->st); ret = virStreamFinish(stream->st);
if (ret < 0) { if (ret < 0) {
remoteDispatchConnError(&rerr, client->conn); remoteDispatchError(&rerr);
return remoteSerializeReplyError(client, &rerr, &msg->hdr); return remoteSerializeReplyError(client, &rerr, &msg->hdr);
} else { } else {
/* Send zero-length confirm */ /* Send zero-length confirm */
@ -569,7 +569,7 @@ remoteStreamHandleRead(struct qemud_client *client,
} else if (ret < 0) { } else if (ret < 0) {
remote_error rerr; remote_error rerr;
memset(&rerr, 0, sizeof rerr); memset(&rerr, 0, sizeof rerr);
remoteDispatchConnError(&rerr, NULL); remoteDispatchError(&rerr);
ret = remoteSerializeStreamError(client, &rerr, stream->procedure, stream->serial); ret = remoteSerializeStreamError(client, &rerr, stream->procedure, stream->serial);
} else { } else {