aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vnc.c18
-rw-r--r--vnc.h1
2 files changed, 11 insertions, 8 deletions
diff --git a/vnc.c b/vnc.c
index 42ff25396f..6b2f7241a8 100644
--- a/vnc.c
+++ b/vnc.c
@@ -508,6 +508,14 @@ void buffer_reset(Buffer *buffer)
buffer->offset = 0;
}
+void buffer_free(Buffer *buffer)
+{
+ qemu_free(buffer->buffer);
+ buffer->offset = 0;
+ buffer->capacity = 0;
+ buffer->buffer = NULL;
+}
+
void buffer_append(Buffer *buffer, const void *data, size_t len)
{
memcpy(buffer->buffer + buffer->offset, data, len);
@@ -961,14 +969,8 @@ static void vnc_disconnect_finish(VncState *vs)
{
vnc_qmp_event(vs, QEVENT_VNC_DISCONNECTED);
- if (vs->input.buffer) {
- qemu_free(vs->input.buffer);
- vs->input.buffer = NULL;
- }
- if (vs->output.buffer) {
- qemu_free(vs->output.buffer);
- vs->output.buffer = NULL;
- }
+ buffer_free(&vs->input);
+ buffer_free(&vs->output);
qobject_decref(vs->info);
diff --git a/vnc.h b/vnc.h
index c8200e90c0..c97113b8ea 100644
--- a/vnc.h
+++ b/vnc.h
@@ -382,6 +382,7 @@ void buffer_reserve(Buffer *buffer, size_t len);
int buffer_empty(Buffer *buffer);
uint8_t *buffer_end(Buffer *buffer);
void buffer_reset(Buffer *buffer);
+void buffer_free(Buffer *buffer);
void buffer_append(Buffer *buffer, const void *data, size_t len);