mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virStream*All: Call virStreamAbort() more frequently
Our documentation to the virStreamRecvAll, virStreamSendAll, virStreamSparseRecvAll, and virStreamSparseSendAll functions indicates that if these functions fail, then virStreamAbort is called. But that is not necessarily true. For instance all of these functions allocate a buffer to work with. If the allocation fails, no virStreamAbort() is called despite -1 being returned. It's the same story with argument sanity checks and a lot of other checks. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
0fe4aa149f
commit
6f8aa8e8da
@ -217,8 +217,10 @@ virStreamSend(virStreamPtr stream,
|
|||||||
* while (1) {
|
* while (1) {
|
||||||
* char buf[1024];
|
* char buf[1024];
|
||||||
* int got = virStreamRecv(st, buf, 1024);
|
* int got = virStreamRecv(st, buf, 1024);
|
||||||
* if (got < 0)
|
* if (got < 0) {
|
||||||
|
* virStreamAbort(st);
|
||||||
* break;
|
* break;
|
||||||
|
* }
|
||||||
* if (got == 0) {
|
* if (got == 0) {
|
||||||
* virStreamFinish(st);
|
* virStreamFinish(st);
|
||||||
* break;
|
* break;
|
||||||
@ -596,10 +598,8 @@ virStreamSendAll(virStreamPtr stream,
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
int got, offset = 0;
|
int got, offset = 0;
|
||||||
got = (handler)(stream, bytes, want, opaque);
|
got = (handler)(stream, bytes, want, opaque);
|
||||||
if (got < 0) {
|
if (got < 0)
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
if (got == 0)
|
if (got == 0)
|
||||||
break;
|
break;
|
||||||
while (offset < got) {
|
while (offset < got) {
|
||||||
@ -615,8 +615,10 @@ virStreamSendAll(virStreamPtr stream,
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(bytes);
|
VIR_FREE(bytes);
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0) {
|
||||||
|
virStreamAbort(stream);
|
||||||
virDispatchError(stream->conn);
|
virDispatchError(stream->conn);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -728,21 +730,16 @@ int virStreamSparseSendAll(virStreamPtr stream,
|
|||||||
const unsigned int skipFlags = 0;
|
const unsigned int skipFlags = 0;
|
||||||
|
|
||||||
if (!dataLen) {
|
if (!dataLen) {
|
||||||
if (holeHandler(stream, &inData, §ionLen, opaque) < 0) {
|
if (holeHandler(stream, &inData, §ionLen, opaque) < 0)
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (!inData && sectionLen) {
|
if (!inData && sectionLen) {
|
||||||
if (virStreamSendHole(stream, sectionLen, skipFlags) < 0) {
|
if (virStreamSendHole(stream, sectionLen, skipFlags) < 0)
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (skipHandler(stream, sectionLen, opaque) < 0) {
|
if (skipHandler(stream, sectionLen, opaque) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("unable to skip hole"));
|
_("unable to skip hole"));
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -755,10 +752,8 @@ int virStreamSparseSendAll(virStreamPtr stream,
|
|||||||
want = dataLen;
|
want = dataLen;
|
||||||
|
|
||||||
got = (handler)(stream, bytes, want, opaque);
|
got = (handler)(stream, bytes, want, opaque);
|
||||||
if (got < 0) {
|
if (got < 0)
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
if (got == 0)
|
if (got == 0)
|
||||||
break;
|
break;
|
||||||
while (offset < got) {
|
while (offset < got) {
|
||||||
@ -775,8 +770,10 @@ int virStreamSparseSendAll(virStreamPtr stream,
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(bytes);
|
VIR_FREE(bytes);
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0) {
|
||||||
|
virStreamAbort(stream);
|
||||||
virDispatchError(stream->conn);
|
virDispatchError(stream->conn);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -857,10 +854,8 @@ virStreamRecvAll(virStreamPtr stream,
|
|||||||
while (offset < got) {
|
while (offset < got) {
|
||||||
int done;
|
int done;
|
||||||
done = (handler)(stream, bytes + offset, got - offset, opaque);
|
done = (handler)(stream, bytes + offset, got - offset, opaque);
|
||||||
if (done < 0) {
|
if (done < 0)
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
offset += done;
|
offset += done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -869,8 +864,10 @@ virStreamRecvAll(virStreamPtr stream,
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(bytes);
|
VIR_FREE(bytes);
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0) {
|
||||||
|
virStreamAbort(stream);
|
||||||
virDispatchError(stream->conn);
|
virDispatchError(stream->conn);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -963,15 +960,11 @@ virStreamSparseRecvAll(virStreamPtr stream,
|
|||||||
|
|
||||||
got = virStreamRecvFlags(stream, bytes, want, flags);
|
got = virStreamRecvFlags(stream, bytes, want, flags);
|
||||||
if (got == -3) {
|
if (got == -3) {
|
||||||
if (virStreamRecvHole(stream, &holeLen, holeFlags) < 0) {
|
if (virStreamRecvHole(stream, &holeLen, holeFlags) < 0)
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (holeHandler(stream, holeLen, opaque) < 0) {
|
if (holeHandler(stream, holeLen, opaque) < 0)
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
} else if (got < 0) {
|
} else if (got < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -981,10 +974,8 @@ virStreamSparseRecvAll(virStreamPtr stream,
|
|||||||
while (offset < got) {
|
while (offset < got) {
|
||||||
int done;
|
int done;
|
||||||
done = (handler)(stream, bytes + offset, got - offset, opaque);
|
done = (handler)(stream, bytes + offset, got - offset, opaque);
|
||||||
if (done < 0) {
|
if (done < 0)
|
||||||
virStreamAbort(stream);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
offset += done;
|
offset += done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -993,8 +984,10 @@ virStreamSparseRecvAll(virStreamPtr stream,
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(bytes);
|
VIR_FREE(bytes);
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0) {
|
||||||
|
virStreamAbort(stream);
|
||||||
virDispatchError(stream->conn);
|
virDispatchError(stream->conn);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user