Skip to content

Commit

Permalink
Unset object to free memory space allocated (memory leak) (#72)
Browse files Browse the repository at this point in the history
* Unset object to free memory space allocated (memory leak in fast snapshot implementation for libafl)

---------

Co-authored-by: Sebastien Foucher <[email protected]>
Co-authored-by: Romain Malmain <[email protected]>
  • Loading branch information
3 people authored May 4, 2024
1 parent 3ebc96e commit a14f8ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions io/channel-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions libafl/syx-snapshot/device-save.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void device_restore_all(DeviceSaveState* dss) {

libafl_restoring_devices = save_libafl_restoring_devices;

object_unref(OBJECT(bioc));
qemu_fclose(f);
}

Expand Down

0 comments on commit a14f8ea

Please sign in to comment.