<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10494">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve; Approved for Submit
Richard Mudgett: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">taskprocessor: Warn on unused result from pushing task.<br><br>Add attribute_warn_unused_result to ast_taskprocessor_push,<br>ast_taskprocessor_push_local and ast_threadpool_push. This will help<br>ensure we perform the necessary cleanup upon failure.<br><br>Change-Id: I7e4079bd7b21cfe52fb431ea79e41314520c3f6d<br>---<br>M apps/app_confbridge.c<br>M include/asterisk/taskprocessor.h<br>M include/asterisk/threadpool.h<br>M main/stasis.c<br>M main/taskprocessor.c<br>M main/threadpool.c<br>M tests/test_taskprocessor.c<br>M tests/test_threadpool.c<br>8 files changed, 161 insertions(+), 57 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_confbridge.c b/apps/app_confbridge.c</span><br><span>index 3a760a9..9c6b690 100644</span><br><span>--- a/apps/app_confbridge.c</span><br><span>+++ b/apps/app_confbridge.c</span><br><span>@@ -1094,13 +1094,15 @@</span><br><span> if (conference->playback_queue) {</span><br><span> struct hangup_data hangup;</span><br><span> hangup_data_init(&hangup, conference);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push(conference->playback_queue, hangup_playback, &hangup);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_mutex_lock(&hangup.lock);</span><br><span style="color: hsl(0, 100%, 40%);">- while (!hangup.hungup) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_cond_wait(&hangup.cond, &hangup.lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_taskprocessor_push(conference->playback_queue, hangup_playback, &hangup)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_lock(&hangup.lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ while (!hangup.hungup) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cond_wait(&hangup.cond, &hangup.lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_unlock(&hangup.lock);</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_mutex_unlock(&hangup.lock);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> hangup_data_destroy(&hangup);</span><br><span> } else {</span><br><span> /* Playback queue is not yet allocated. Just hang up the channel straight */</span><br><span>diff --git a/include/asterisk/taskprocessor.h b/include/asterisk/taskprocessor.h</span><br><span>index 7c79036..f74989a 100644</span><br><span>--- a/include/asterisk/taskprocessor.h</span><br><span>+++ b/include/asterisk/taskprocessor.h</span><br><span>@@ -213,7 +213,8 @@</span><br><span> * \retval -1 failure</span><br><span> * \since 1.6.1</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-int ast_taskprocessor_push(struct ast_taskprocessor *tps, int (*task_exe)(void *datap), void *datap);</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_taskprocessor_push(struct ast_taskprocessor *tps, int (*task_exe)(void *datap), void *datap)</span><br><span style="color: hsl(120, 100%, 40%);">+ attribute_warn_unused_result;</span><br><span> </span><br><span> /*! \brief Local data parameter */</span><br><span> struct ast_taskprocessor_local {</span><br><span>@@ -239,7 +240,8 @@</span><br><span> * \since 12.0.0</span><br><span> */</span><br><span> int ast_taskprocessor_push_local(struct ast_taskprocessor *tps,</span><br><span style="color: hsl(0, 100%, 40%);">- int (*task_exe)(struct ast_taskprocessor_local *local), void *datap);</span><br><span style="color: hsl(120, 100%, 40%);">+ int (*task_exe)(struct ast_taskprocessor_local *local), void *datap)</span><br><span style="color: hsl(120, 100%, 40%);">+ attribute_warn_unused_result;</span><br><span> </span><br><span> /*!</span><br><span> * \brief Indicate the taskprocessor is suspended.</span><br><span>diff --git a/include/asterisk/threadpool.h b/include/asterisk/threadpool.h</span><br><span>index 0f360c7..77ab8a8 100644</span><br><span>--- a/include/asterisk/threadpool.h</span><br><span>+++ b/include/asterisk/threadpool.h</span><br><span>@@ -186,7 +186,8 @@</span><br><span> * \retval 0 success</span><br><span> * \retval -1 failure</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-int ast_threadpool_push(struct ast_threadpool *pool, int (*task)(void *data), void *data);</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_threadpool_push(struct ast_threadpool *pool, int (*task)(void *data), void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+ attribute_warn_unused_result;</span><br><span> </span><br><span> /*!</span><br><span> * \brief Shut down a threadpool and destroy it</span><br><span>diff --git a/main/stasis.c b/main/stasis.c</span><br><span>index bfaf4fb..26e404c 100644</span><br><span>--- a/main/stasis.c</span><br><span>+++ b/main/stasis.c</span><br><span>@@ -563,7 +563,10 @@</span><br><span> </span><br><span> /* When all that's done, remove the ref the mailbox has on the sub */</span><br><span> if (sub->mailbox) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push(sub->mailbox, sub_cleanup, sub);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_push(sub->mailbox, sub_cleanup, sub)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Nothing we can do here, the conditional is just to keep</span><br><span style="color: hsl(120, 100%, 40%);">+ * the compiler happy that we're not ignoring the result. */</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> /* Unsubscribing unrefs the subscription */</span><br><span>diff --git a/main/taskprocessor.c b/main/taskprocessor.c</span><br><span>index 7577715..baba2ff 100644</span><br><span>--- a/main/taskprocessor.c</span><br><span>+++ b/main/taskprocessor.c</span><br><span>@@ -237,7 +237,11 @@</span><br><span> /* Hold a reference during shutdown */</span><br><span> ao2_t_ref(listener->tps, +1, "tps-shutdown");</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push(listener->tps, default_listener_die, pvt);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_push(listener->tps, default_listener_die, pvt)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* This will cause the thread to exit early without completing tasks already</span><br><span style="color: hsl(120, 100%, 40%);">+ * in the queue. This is probably the least bad option in this situation. */</span><br><span style="color: hsl(120, 100%, 40%);">+ default_listener_die(pvt);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> ast_assert(pvt->poll_thread != AST_PTHREADT_NULL);</span><br><span> </span><br><span>diff --git a/main/threadpool.c b/main/threadpool.c</span><br><span>index e7abc8f..7729930 100644</span><br><span>--- a/main/threadpool.c</span><br><span>+++ b/main/threadpool.c</span><br><span>@@ -658,7 +658,9 @@</span><br><span> }</span><br><span> </span><br><span> if (pool->listener && pool->listener->callbacks->emptied) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push(pool->control_tps, queued_emptied, pool);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_push(pool->control_tps, queued_emptied, pool)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Nothing to do here but we need the check to keep the compiler happy. */</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c</span><br><span>index 273e045..6428746 100644</span><br><span>--- a/tests/test_taskprocessor.c</span><br><span>+++ b/tests/test_taskprocessor.c</span><br><span>@@ -151,7 +151,10 @@</span><br><span> return AST_TEST_FAIL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push(tps, task, task_data);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_push(tps, task, task_data)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Failed to queue task\n");</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> </span><br><span> res = task_wait(task_data);</span><br><span> if (res != 0) {</span><br><span>@@ -240,7 +243,11 @@</span><br><span> </span><br><span> for (i = 0; i < NUM_TASKS; ++i) {</span><br><span> rand_data[i] = ast_random();</span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push(tps, load_task, &rand_data[i]);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_push(tps, load_task, &rand_data[i])) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Failed to queue task\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ goto test_end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> ast_mutex_lock(&load_task_results.lock);</span><br><span>@@ -438,14 +445,22 @@</span><br><span> goto test_exit;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push(tps, listener_test_task, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_push(tps, listener_test_task, NULL)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Failed to queue task\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ goto test_exit;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (check_stats(test, pvt, 1, 0, 1) < 0) {</span><br><span> res = AST_TEST_FAIL;</span><br><span> goto test_exit;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push(tps, listener_test_task, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_push(tps, listener_test_task, NULL)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Failed to queue task\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ goto test_exit;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (check_stats(test, pvt, 2, 0, 1) < 0) {</span><br><span> res = AST_TEST_FAIL;</span><br><span>@@ -710,7 +725,10 @@</span><br><span> local_data = 0;</span><br><span> ast_taskprocessor_set_local(tps, &local_data);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_push_local(tps, local_task_exe, task_data);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_taskprocessor_push_local(tps, local_task_exe, task_data)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Failed to queue task\n");</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> </span><br><span> res = task_wait(task_data);</span><br><span> if (res != 0) {</span><br><span>diff --git a/tests/test_threadpool.c b/tests/test_threadpool.c</span><br><span>index d8acf26..3fb4430 100644</span><br><span>--- a/tests/test_threadpool.c</span><br><span>+++ b/tests/test_threadpool.c</span><br><span>@@ -127,6 +127,18 @@</span><br><span> return std;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void simple_task_data_free(struct simple_task_data *std)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!std) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_destroy(&std->lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cond_destroy(&std->cond);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(std);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int simple_task(void *data)</span><br><span> {</span><br><span> struct simple_task_data *std = data;</span><br><span>@@ -319,7 +331,9 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> wait_for_task_pushed(listener);</span><br><span> </span><br><span>@@ -328,7 +342,7 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> }</span><br><span>@@ -635,11 +649,13 @@</span><br><span> }</span><br><span> ast_mutex_unlock(&tld->lock);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = wait_for_completion(test, std);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- res = wait_for_completion(test, std);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std);</span><br><span> </span><br><span> if (res == AST_TEST_FAIL) {</span><br><span> goto end;</span><br><span>@@ -707,7 +723,9 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> ast_threadpool_set_size(pool, 1);</span><br><span> </span><br><span>@@ -736,7 +754,7 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> </span><br><span>@@ -796,7 +814,10 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> res = wait_for_completion(test, std);</span><br><span> if (res == AST_TEST_FAIL) {</span><br><span>@@ -819,7 +840,7 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> }</span><br><span>@@ -882,9 +903,18 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std2);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std3);</span><br><span style="color: hsl(120, 100%, 40%);">+ res = AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std2)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std3)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> res = wait_for_completion(test, std1);</span><br><span> if (res == AST_TEST_FAIL) {</span><br><span>@@ -914,9 +944,9 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std2);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std3);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std1);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std2);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std3);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> }</span><br><span>@@ -1011,7 +1041,9 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std1);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> /* Pushing the task should result in the threadpool growing</span><br><span> * by three threads. This will allow the task to actually execute</span><br><span>@@ -1034,9 +1066,19 @@</span><br><span> /* Now push three tasks into the pool and ensure the pool does not</span><br><span> * grow.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std2);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std3);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std4);</span><br><span style="color: hsl(120, 100%, 40%);">+ res = AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std2)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std3)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std4)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> res = wait_for_completion(test, std2);</span><br><span> if (res == AST_TEST_FAIL) {</span><br><span>@@ -1064,10 +1106,10 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std2);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std3);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std4);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std1);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std2);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std3);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std4);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> }</span><br><span>@@ -1121,7 +1163,9 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> res = wait_for_completion(test, std);</span><br><span> if (res == AST_TEST_FAIL) {</span><br><span>@@ -1137,7 +1181,7 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> }</span><br><span>@@ -1193,7 +1237,9 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std1);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> ast_threadpool_set_size(pool, 1);</span><br><span> </span><br><span>@@ -1218,7 +1264,10 @@</span><br><span> }</span><br><span> </span><br><span> /* Now make sure the threadpool reactivates when we add a second task */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, simple_task, std2);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, simple_task, std2)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> res = wait_for_completion(test, std2);</span><br><span> if (res == AST_TEST_FAIL) {</span><br><span>@@ -1240,8 +1289,8 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(std2);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std1);</span><br><span style="color: hsl(120, 100%, 40%);">+ simple_task_data_free(std2);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> </span><br><span>@@ -1269,6 +1318,19 @@</span><br><span> return ctd;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void complex_task_data_free(struct complex_task_data *ctd)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ctd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_destroy(&ctd->lock);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cond_destroy(&ctd->stall_cond);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cond_destroy(&ctd->notify_cond);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(ctd);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int complex_task(void *data)</span><br><span> {</span><br><span> struct complex_task_data *ctd = data;</span><br><span>@@ -1400,8 +1462,13 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, complex_task, ctd1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, complex_task, ctd2);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, complex_task, ctd1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, complex_task, ctd2)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> ast_threadpool_set_size(pool, 2);</span><br><span> </span><br><span>@@ -1438,8 +1505,8 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(ctd1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(ctd2);</span><br><span style="color: hsl(120, 100%, 40%);">+ complex_task_data_free(ctd1);</span><br><span style="color: hsl(120, 100%, 40%);">+ complex_task_data_free(ctd2);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> }</span><br><span>@@ -1496,8 +1563,13 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, complex_task, ctd1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_threadpool_push(pool, complex_task, ctd2);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, complex_task, ctd1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_threadpool_push(pool, complex_task, ctd2)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> ast_threadpool_set_size(pool, 4);</span><br><span> </span><br><span>@@ -1549,8 +1621,8 @@</span><br><span> end:</span><br><span> ast_threadpool_shutdown(pool);</span><br><span> ao2_cleanup(listener);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(ctd1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(ctd2);</span><br><span style="color: hsl(120, 100%, 40%);">+ complex_task_data_free(ctd1);</span><br><span style="color: hsl(120, 100%, 40%);">+ complex_task_data_free(ctd2);</span><br><span> ast_free(tld);</span><br><span> return res;</span><br><span> }</span><br><span>@@ -1666,9 +1738,9 @@</span><br><span> poke_worker(data3);</span><br><span> ast_taskprocessor_unreference(uut);</span><br><span> ast_threadpool_shutdown(pool);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(data1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(data2);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(data3);</span><br><span style="color: hsl(120, 100%, 40%);">+ complex_task_data_free(data1);</span><br><span style="color: hsl(120, 100%, 40%);">+ complex_task_data_free(data2);</span><br><span style="color: hsl(120, 100%, 40%);">+ complex_task_data_free(data3);</span><br><span> return res;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10494">change 10494</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/10494"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I7e4079bd7b21cfe52fb431ea79e41314520c3f6d </div>
<div style="display:none"> Gerrit-Change-Number: 10494 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>