Skip to content

Commit

Permalink
Merge pull request ceph#56596 from tchaikov/wip-on-exit-fix-leaks
Browse files Browse the repository at this point in the history
test/on_exit: use static variables for on_exit hooks

Reviewed-by: Radoslaw Zarzynski <[email protected]>
  • Loading branch information
tchaikov authored Apr 2, 2024
2 parents 632828c + 42db62c commit 1abd6ea
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/test/on_exit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ static void func_scope(void)
{
OnExitManager mgr;

int *inc_1 = (int*)malloc(sizeof(*inc_1));
*inc_1 = 5;
mgr.add_callback(add, inc_1);
static int inc_1 = 5;
mgr.add_callback(add, &inc_1);

int *inc_2 = (int*)malloc(sizeof(*inc_2));
*inc_2 = 3;
mgr.add_callback(add, inc_2);
static int inc_2 = 3;
mgr.add_callback(add, &inc_2);
}

// shared between processes
Expand Down Expand Up @@ -84,9 +82,8 @@ int main(int argc, char **argv)
// exits by returning from main. The parent checks the value after the
// child exits via the memory map.
ceph_assert(*shared_val == 0);
int *new_val = (int*)malloc(sizeof(*new_val));
*new_val = MAIN_SCOPE_VAL;
main_scope_mgr.add_callback(main_scope_cb, new_val);
static int new_val = MAIN_SCOPE_VAL;
main_scope_mgr.add_callback(main_scope_cb, &new_val);
return 0;
}

Expand All @@ -104,9 +101,8 @@ int main(int argc, char **argv)
// child adds a callback to the static scope callback manager and then
// exits via exit().
ceph_assert(*shared_val == 0);
int *new_val = (int*)malloc(sizeof(*new_val));
*new_val = EXIT_FUNC_VAL;
exit_func_mgr.add_callback(exit_func_cb, new_val);
static int new_val = EXIT_FUNC_VAL;
exit_func_mgr.add_callback(exit_func_cb, &new_val);
call_exit();
ceph_abort();
}
Expand Down

0 comments on commit 1abd6ea

Please sign in to comment.