Skip to content

Commit

Permalink
Fix memleak (#1811)
Browse files Browse the repository at this point in the history
  • Loading branch information
tklengyel authored Sep 27, 2024
1 parent a7a799f commit 21c8df9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/libinjector/win/win_injector.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,11 +774,13 @@ void injector_terminate_on_win(drakvuf_t drakvuf,
uint32_t injection_tid,
vmi_pid_t pid)
{
injector_t injector = (injector_t)g_try_malloc0(sizeof(struct injector));
if ( !injector )
return;

PRINT_DEBUG("Target PID %u to terminate %u\n", injection_pid, pid);
drakvuf_interrupt(drakvuf, 0); // clean

injector_t injector = (injector_t)g_try_malloc0(sizeof(struct injector));

injector->method = INJECT_METHOD_TERMINATEPROC;
injector->drakvuf = drakvuf;
injector->target_pid = injection_pid;
Expand All @@ -805,11 +807,13 @@ void injector_exitthread_on_win(drakvuf_t drakvuf,
vmi_pid_t injection_pid,
uint32_t injection_tid)
{
injector_t injector = (injector_t)g_try_malloc0(sizeof(struct injector));
if ( !injector )
return;

PRINT_DEBUG("Target PID %u to terminate TID %u\n", injection_pid, injection_tid);
drakvuf_interrupt(drakvuf, 0); // clean

injector_t injector = (injector_t)g_try_malloc0(sizeof(struct injector));

injector->method = INJECT_METHOD_EXITTHREAD;
injector->drakvuf = drakvuf;
injector->target_pid = injection_pid;
Expand Down
5 changes: 3 additions & 2 deletions src/libinjector/win/win_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,15 @@ addr_t get_function_va(drakvuf_t drakvuf, addr_t eprocess_base, char const* lib,
void free_memtraps(injector_t injector)
{
GSList* loop = injector->memtraps;
injector->memtraps = NULL;

while (loop)
{
drakvuf_remove_trap(injector->drakvuf, loop->data, (drakvuf_trap_free_t)free);
loop = loop->next;
}
g_slist_free(loop);

g_slist_free(injector->memtraps);
injector->memtraps = NULL;
}

void free_injector(injector_t injector)
Expand Down

0 comments on commit 21c8df9

Please sign in to comment.