Skip to content

Commit 1abd6ea

Browse files
authored
Merge pull request ceph#56596 from tchaikov/wip-on-exit-fix-leaks
test/on_exit: use static variables for on_exit hooks Reviewed-by: Radoslaw Zarzynski <[email protected]>
2 parents 632828c + 42db62c commit 1abd6ea

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/test/on_exit.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ static void func_scope(void)
2626
{
2727
OnExitManager mgr;
2828

29-
int *inc_1 = (int*)malloc(sizeof(*inc_1));
30-
*inc_1 = 5;
31-
mgr.add_callback(add, inc_1);
29+
static int inc_1 = 5;
30+
mgr.add_callback(add, &inc_1);
3231

33-
int *inc_2 = (int*)malloc(sizeof(*inc_2));
34-
*inc_2 = 3;
35-
mgr.add_callback(add, inc_2);
32+
static int inc_2 = 3;
33+
mgr.add_callback(add, &inc_2);
3634
}
3735

3836
// shared between processes
@@ -84,9 +82,8 @@ int main(int argc, char **argv)
8482
// exits by returning from main. The parent checks the value after the
8583
// child exits via the memory map.
8684
ceph_assert(*shared_val == 0);
87-
int *new_val = (int*)malloc(sizeof(*new_val));
88-
*new_val = MAIN_SCOPE_VAL;
89-
main_scope_mgr.add_callback(main_scope_cb, new_val);
85+
static int new_val = MAIN_SCOPE_VAL;
86+
main_scope_mgr.add_callback(main_scope_cb, &new_val);
9087
return 0;
9188
}
9289

@@ -104,9 +101,8 @@ int main(int argc, char **argv)
104101
// child adds a callback to the static scope callback manager and then
105102
// exits via exit().
106103
ceph_assert(*shared_val == 0);
107-
int *new_val = (int*)malloc(sizeof(*new_val));
108-
*new_val = EXIT_FUNC_VAL;
109-
exit_func_mgr.add_callback(exit_func_cb, new_val);
104+
static int new_val = EXIT_FUNC_VAL;
105+
exit_func_mgr.add_callback(exit_func_cb, &new_val);
110106
call_exit();
111107
ceph_abort();
112108
}

0 commit comments

Comments
 (0)