Skip to content
Snippets Groups Projects
Commit c4037d4a authored by Sean Bright's avatar Sean Bright Committed by Friendly Automation
Browse files

test_abstract_jb.c: Fix put and put_out_of_order memory leaks.

We can't rely on RAII_VAR(...) to properly clean up data that is
allocated within a loop.

ASTERISK-27176 #close

Change-Id: Ib575616101230c4f603519114ec62ebf3936882c
parent e0111a56
No related branches found
No related tags found
3 merge requests!138Merge branch asterisk-20.3.0 into devel properly,!123Merge asterisk '20.3.0' into devel,!118Draft: manager: AOC-S support for AOCMessage
......@@ -293,8 +293,8 @@ static struct ast_jb default_jb = {
RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \
const struct ast_jb_impl *impl; \
struct ast_jb_conf conf; \
RAII_VAR(struct ast_frame *, expected_frame, NULL, ast_frame_dtor); \
RAII_VAR(struct ast_frame *, actual_frame, NULL, ast_frame_dtor); \
struct ast_frame *expected_frame = NULL; \
struct ast_frame *actual_frame = NULL; \
int res; \
long next; \
int i; \
......@@ -318,7 +318,15 @@ static struct ast_jb default_jb = {
jb->impl = impl; \
\
expected_frame = create_test_frame(1000, 0); \
jb->impl->put_first(jb->jbobj, expected_frame, 1100); \
res = jb->impl->put_first(jb->jbobj, \
expected_frame, \
1100); \
if (res != AST_JB_IMPL_OK) { \
ast_test_status_update(test, "Error: On first frame, got %d back from put_first (expected %d)\n", \
res, AST_JB_IMPL_OK); \
ast_frame_dtor(expected_frame); \
return AST_TEST_FAIL; \
} \
for (i = 1; i < 10; i++) { \
expected_frame = create_test_frame(1000 + i * DEFAULT_FRAME_MS, 0); \
res = jb->impl->put(jb->jbobj, \
......@@ -327,6 +335,7 @@ static struct ast_jb default_jb = {
if (res != AST_JB_IMPL_OK) { \
ast_test_status_update(test, "Error: On frame %d, got %d back from put (expected %d)\n", \
i, res, AST_JB_IMPL_OK); \
ast_frame_dtor(expected_frame); \
return AST_TEST_FAIL; \
} \
} \
......@@ -338,11 +347,12 @@ static struct ast_jb default_jb = {
if (res != AST_JB_IMPL_OK) { \
ast_test_status_update(test, "Error: failed to retrieve frame %i at time %ld\n", \
i, next); \
ast_frame_dtor(expected_frame); \
return AST_TEST_FAIL; \
} \
VERIFY_FRAME(actual_frame, expected_frame); \
ast_frfree(expected_frame); \
expected_frame = NULL; \
ast_frame_dtor(expected_frame); \
ast_frame_dtor(actual_frame); \
} \
return AST_TEST_PASS; \
}
......@@ -427,8 +437,8 @@ static struct ast_jb default_jb = {
RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \
const struct ast_jb_impl *impl; \
struct ast_jb_conf conf; \
RAII_VAR(struct ast_frame *, actual_frame, NULL, ast_frame_dtor); \
RAII_VAR(struct ast_frame *, expected_frame, NULL, ast_frame_dtor); \
struct ast_frame *expected_frame = NULL; \
struct ast_frame *actual_frame = NULL; \
int res; \
long next; \
int i; \
......@@ -454,7 +464,13 @@ static struct ast_jb default_jb = {
jb->impl = impl; \
\
expected_frame = create_test_frame(1000, 0); \
jb->impl->put_first(jb->jbobj, expected_frame, 1100); \
res = jb->impl->put_first(jb->jbobj, expected_frame, 1100); \
if (res != AST_JB_IMPL_OK) { \
ast_test_status_update(test, "Error: On first frame, got %d back from put_first (expected %d)\n", \
res, AST_JB_IMPL_OK); \
ast_frame_dtor(expected_frame); \
return AST_TEST_FAIL; \
} \
for (i = 1; i <= 10; i++) { \
if (i % 3 == 1 && i != 10) { \
expected_frame = create_test_frame(1000 + ((i + 1) * DEFAULT_FRAME_MS), 0); \
......@@ -469,6 +485,7 @@ static struct ast_jb default_jb = {
if (res != AST_JB_IMPL_OK) { \
ast_test_status_update(test, "Error: On frame %d, got %d back from put (expected %d)\n", \
i, res, AST_JB_IMPL_OK); \
ast_frame_dtor(expected_frame); \
return AST_TEST_FAIL; \
} \
} \
......@@ -480,10 +497,12 @@ static struct ast_jb default_jb = {
if (res != AST_JB_IMPL_OK) { \
ast_test_status_update(test, "Error: failed to retrieve frame at %ld\n", \
next); \
ast_frame_dtor(expected_frame); \
return AST_TEST_FAIL; \
} \
VERIFY_FRAME(actual_frame, expected_frame); \
ast_frfree(expected_frame); \
ast_frame_dtor(expected_frame); \
ast_frame_dtor(actual_frame); \
expected_frame = NULL; \
} \
\
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment