Fix possible double free during context destruction
This commit is contained in:
@ -55,12 +55,16 @@ int main(int argc, const char **argv) {
|
||||
|
||||
ctx_and_flag.ctx = c;
|
||||
|
||||
A static_a = {
|
||||
.num = 0,
|
||||
.str = counting_strdup("static"),
|
||||
.next = make_a(c, 0, "in static"),
|
||||
};
|
||||
refcount_context_init_static(c, &static_a);
|
||||
#define STATIC_A(id) \
|
||||
A static_a_##id = { \
|
||||
.num = __LINE__, \
|
||||
.str = counting_strdup("static " #id), \
|
||||
.next = make_a(c, 0, "in static " #id), \
|
||||
}; \
|
||||
refcount_context_init_static(c, &static_a_##id)
|
||||
STATIC_A(1);
|
||||
STATIC_A(2);
|
||||
STATIC_A(3);
|
||||
|
||||
A *a = make_a(c, 10, "Hello world\n");
|
||||
assert(!refcount_context_is_static(c, a));
|
||||
@ -187,10 +191,12 @@ int main(int argc, const char **argv) {
|
||||
assert(refcount_context_num_refs(c, a) == 1);
|
||||
assert(!refcount_context_unref(c, a));
|
||||
|
||||
refcount_context_deinit_static(c, &static_a);
|
||||
counting_free(static_a.str);
|
||||
refcount_context_deinit_static(c, &static_a_1);
|
||||
counting_free(static_a_1.str);
|
||||
|
||||
refcount_context_destroy(c);
|
||||
counting_free(static_a_2.str);
|
||||
counting_free(static_a_3.str);
|
||||
|
||||
check_allocator_status();
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user