Skip to content

Commit

Permalink
lib-test: Fixed assert-crash in test_exit() with --enable-static-checker
Browse files Browse the repository at this point in the history
Fixes:
Panic: Missing t_pop() call
  • Loading branch information
sirainen authored and GitLab committed Oct 5, 2016
1 parent ceace05 commit b106236
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/lib-test/test-common.c
Expand Up @@ -328,10 +328,7 @@ test_exit(int status)
{
i_free_and_null(expected_error_str);
i_free_and_null(test_prefix);
#ifndef STATIC_CHECKER
data_stack_frame_t id = 0;
(void)t_pop(&id); /* as we were within a T_BEGIN { tests[i].func(); } T_END */
#endif
t_pop_last_unsafe(); /* as we were within a T_BEGIN { tests[i].func(); } T_END */
lib_deinit();
_exit(status);
}
12 changes: 9 additions & 3 deletions src/lib/data-stack.c
Expand Up @@ -274,7 +274,7 @@ static void t_pop_verify(void)
}
#endif

bool t_pop(data_stack_frame_t *id)
void t_pop_last_unsafe(void)
{
struct stack_frame_block *frame_block;

Expand Down Expand Up @@ -320,15 +320,21 @@ bool t_pop(data_stack_frame_t *id)
frame_block->prev = unused_frame_blocks;
unused_frame_blocks = frame_block;
}
data_stack_frame_id--;
}

bool t_pop(data_stack_frame_t *id)
{
t_pop_last_unsafe();
#ifndef STATIC_CHECKER
if (unlikely(--data_stack_frame_id != *id))
if (unlikely(data_stack_frame_id != *id))
return FALSE;
*id = 0;
#else
unsigned int frame_id = (*id)->id;
i_free_and_null(*id);

if (unlikely(--data_stack_frame_id != frame_id))
if (unlikely(data_stack_frame_id != frame_id))
return FALSE;
#endif
return TRUE;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/data-stack.h
Expand Up @@ -54,6 +54,8 @@ data_stack_frame_t t_push_named(const char *format, ...) ATTR_HOT ATTR_FORMAT(1,
/* Returns TRUE on success, FALSE if t_pop() call was leaked. The caller
should panic. */
bool t_pop(data_stack_frame_t *id) ATTR_HOT;
/* Pop the last data stack frame. This shouldn't be called outside test code. */
void t_pop_last_unsafe(void);

/* Usage: T_BEGIN { code } T_END */
#ifndef DEBUG
Expand Down

0 comments on commit b106236

Please sign in to comment.