<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16453">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">test_abstract_jb.c: Fix put and put_out_of_order memory leaks.<br><br>We can't rely on RAII_VAR(...) to properly clean up data that is<br>allocated within a loop.<br><br>ASTERISK-27176 #close<br><br>Change-Id: Ib575616101230c4f603519114ec62ebf3936882c<br>---<br>M tests/test_abstract_jb.c<br>1 file changed, 28 insertions(+), 9 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/tests/test_abstract_jb.c b/tests/test_abstract_jb.c</span><br><span>index 53614bc..76eb4bf 100644</span><br><span>--- a/tests/test_abstract_jb.c</span><br><span>+++ b/tests/test_abstract_jb.c</span><br><span>@@ -293,8 +293,8 @@</span><br><span> RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \</span><br><span> const struct ast_jb_impl *impl; \</span><br><span> struct ast_jb_conf conf; \</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_frame *, expected_frame, NULL, ast_frame_dtor); \</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_frame *, actual_frame, NULL, ast_frame_dtor); \</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_frame *expected_frame = NULL; \</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_frame *actual_frame = NULL; \</span><br><span> int res; \</span><br><span> long next; \</span><br><span> int i; \</span><br><span>@@ -318,7 +318,15 @@</span><br><span> jb->impl = impl; \</span><br><span> \</span><br><span> expected_frame = create_test_frame(1000, 0); \</span><br><span style="color: hsl(0, 100%, 40%);">- jb->impl->put_first(jb->jbobj, expected_frame, 1100); \</span><br><span style="color: hsl(120, 100%, 40%);">+ res = jb->impl->put_first(jb->jbobj, \</span><br><span style="color: hsl(120, 100%, 40%);">+ expected_frame, \</span><br><span style="color: hsl(120, 100%, 40%);">+ 1100); \</span><br><span style="color: hsl(120, 100%, 40%);">+ if (res != AST_JB_IMPL_OK) { \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Error: On first frame, got %d back from put_first (expected %d)\n", \</span><br><span style="color: hsl(120, 100%, 40%);">+ res, AST_JB_IMPL_OK); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(expected_frame); \</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_FAIL; \</span><br><span style="color: hsl(120, 100%, 40%);">+ } \</span><br><span> for (i = 1; i < 10; i++) { \</span><br><span> expected_frame = create_test_frame(1000 + i * DEFAULT_FRAME_MS, 0); \</span><br><span> res = jb->impl->put(jb->jbobj, \</span><br><span>@@ -327,6 +335,7 @@</span><br><span> if (res != AST_JB_IMPL_OK) { \</span><br><span> ast_test_status_update(test, "Error: On frame %d, got %d back from put (expected %d)\n", \</span><br><span> i, res, AST_JB_IMPL_OK); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(expected_frame); \</span><br><span> return AST_TEST_FAIL; \</span><br><span> } \</span><br><span> } \</span><br><span>@@ -338,11 +347,12 @@</span><br><span> if (res != AST_JB_IMPL_OK) { \</span><br><span> ast_test_status_update(test, "Error: failed to retrieve frame %i at time %ld\n", \</span><br><span> i, next); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(expected_frame); \</span><br><span> return AST_TEST_FAIL; \</span><br><span> } \</span><br><span> VERIFY_FRAME(actual_frame, expected_frame); \</span><br><span style="color: hsl(0, 100%, 40%);">- ast_frfree(expected_frame); \</span><br><span style="color: hsl(0, 100%, 40%);">- expected_frame = NULL; \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(expected_frame); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(actual_frame); \</span><br><span> } \</span><br><span> return AST_TEST_PASS; \</span><br><span> }</span><br><span>@@ -427,8 +437,8 @@</span><br><span> RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \</span><br><span> const struct ast_jb_impl *impl; \</span><br><span> struct ast_jb_conf conf; \</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_frame *, actual_frame, NULL, ast_frame_dtor); \</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_frame *, expected_frame, NULL, ast_frame_dtor); \</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_frame *expected_frame = NULL; \</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_frame *actual_frame = NULL; \</span><br><span> int res; \</span><br><span> long next; \</span><br><span> int i; \</span><br><span>@@ -454,7 +464,13 @@</span><br><span> jb->impl = impl; \</span><br><span> \</span><br><span> expected_frame = create_test_frame(1000, 0); \</span><br><span style="color: hsl(0, 100%, 40%);">- jb->impl->put_first(jb->jbobj, expected_frame, 1100); \</span><br><span style="color: hsl(120, 100%, 40%);">+ res = jb->impl->put_first(jb->jbobj, expected_frame, 1100); \</span><br><span style="color: hsl(120, 100%, 40%);">+ if (res != AST_JB_IMPL_OK) { \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Error: On first frame, got %d back from put_first (expected %d)\n", \</span><br><span style="color: hsl(120, 100%, 40%);">+ res, AST_JB_IMPL_OK); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(expected_frame); \</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_FAIL; \</span><br><span style="color: hsl(120, 100%, 40%);">+ } \</span><br><span> for (i = 1; i <= 10; i++) { \</span><br><span> if (i % 3 == 1 && i != 10) { \</span><br><span> expected_frame = create_test_frame(1000 + ((i + 1) * DEFAULT_FRAME_MS), 0); \</span><br><span>@@ -469,6 +485,7 @@</span><br><span> if (res != AST_JB_IMPL_OK) { \</span><br><span> ast_test_status_update(test, "Error: On frame %d, got %d back from put (expected %d)\n", \</span><br><span> i, res, AST_JB_IMPL_OK); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(expected_frame); \</span><br><span> return AST_TEST_FAIL; \</span><br><span> } \</span><br><span> } \</span><br><span>@@ -480,10 +497,12 @@</span><br><span> if (res != AST_JB_IMPL_OK) { \</span><br><span> ast_test_status_update(test, "Error: failed to retrieve frame at %ld\n", \</span><br><span> next); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(expected_frame); \</span><br><span> return AST_TEST_FAIL; \</span><br><span> } \</span><br><span> VERIFY_FRAME(actual_frame, expected_frame); \</span><br><span style="color: hsl(0, 100%, 40%);">- ast_frfree(expected_frame); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(expected_frame); \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frame_dtor(actual_frame); \</span><br><span> expected_frame = NULL; \</span><br><span> } \</span><br><span> \</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16453">change 16453</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16453"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ib575616101230c4f603519114ec62ebf3936882c </div>
<div style="display:none"> Gerrit-Change-Number: 16453 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>