From a14f8eae8e467f24a8ae79868a0736a46123ca02 Mon Sep 17 00:00:00 2001 From: Sebastien Foucher Date: Sat, 4 May 2024 13:41:10 +0200 Subject: [PATCH] Unset object to free memory space allocated (memory leak) (#72) * Unset object to free memory space allocated (memory leak in fast snapshot implementation for libafl) --------- Co-authored-by: Sebastien Foucher Co-authored-by: Romain Malmain --- io/channel-buffer.c | 11 ++++++----- libafl/syx-snapshot/device-save.c | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/io/channel-buffer.c b/io/channel-buffer.c index 60cd33587b..bd3256df92 100644 --- a/io/channel-buffer.c +++ b/io/channel-buffer.c @@ -35,12 +35,12 @@ qio_channel_buffer_new(size_t capacity) if (capacity) { ioc->data = g_new0(uint8_t, capacity); ioc->capacity = capacity; - - //// --- Begin LibAFL code --- - ioc->internal_allocation = true; - //// --- End LibAFL code --- } + //// --- Begin LibAFL code --- + ioc->internal_allocation = capacity > 0; + //// --- End LibAFL code --- + return ioc; } @@ -75,6 +75,7 @@ static void qio_channel_buffer_finalize(Object *obj) g_free(ioc->data); } + ioc->data = NULL; //// --- End LibAFL code --- // g_free(ioc->data); @@ -181,8 +182,8 @@ static int qio_channel_buffer_close(QIOChannel *ioc, g_free(bioc->data); } - //g_free(bioc->data); //// --- End LibAFL code --- + //g_free(bioc->data); bioc->data = NULL; bioc->capacity = bioc->usage = bioc->offset = 0; diff --git a/libafl/syx-snapshot/device-save.c b/libafl/syx-snapshot/device-save.c index 38e6e1bac6..2df2442761 100644 --- a/libafl/syx-snapshot/device-save.c +++ b/libafl/syx-snapshot/device-save.c @@ -99,6 +99,7 @@ void device_restore_all(DeviceSaveState* dss) { libafl_restoring_devices = save_libafl_restoring_devices; + object_unref(OBJECT(bioc)); qemu_fclose(f); }