<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7920">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stasis_bridges: Remove silly usage of RAII_VAR.<br><br>Change-Id: I0fa7ab05454f183dc4ff10e26d18776d2b0fcf1f<br>---<br>M main/stasis_bridges.c<br>1 file changed, 58 insertions(+), 44 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/20/7920/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/stasis_bridges.c b/main/stasis_bridges.c<br>index d197e4d..4b68559 100644<br>--- a/main/stasis_bridges.c<br>+++ b/main/stasis_bridges.c<br>@@ -233,7 +233,7 @@<br> <br> struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge)<br> {<br>- RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);<br>+ struct ast_bridge_snapshot *snapshot;<br> struct ast_bridge_channel *bridge_channel;<br> <br> if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {<br>@@ -249,17 +249,22 @@<br> if (ast_string_field_init(snapshot, 128)<br> || ast_string_field_init_extended(snapshot, video_source_id)) {<br> ao2_ref(snapshot, -1);<br>+<br> return NULL;<br> }<br> <br> snapshot->channels = ast_str_container_alloc(SNAPSHOT_CHANNELS_BUCKETS);<br> if (!snapshot->channels) {<br>+ ao2_ref(snapshot, -1);<br>+<br> return NULL;<br> }<br> <br> AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {<br> if (ast_str_container_add(snapshot->channels,<br> ast_channel_uniqueid(bridge_channel->chan))) {<br>+ ao2_ref(snapshot, -1);<br>+<br> return NULL;<br> }<br> }<br>@@ -285,14 +290,13 @@<br> ast_channel_uniqueid(bridge->softmix.video_mode.mode_data.talker_src_data.chan_vsrc));<br> }<br> <br>- ao2_ref(snapshot, +1);<br> return snapshot;<br> }<br> <br> void ast_bridge_publish_state(struct ast_bridge *bridge)<br> {<br>- RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);<br>- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);<br>+ struct ast_bridge_snapshot *snapshot;<br>+ struct stasis_message *msg;<br> <br> if (!ast_bridge_snapshot_type()) {<br> return;<br>@@ -306,17 +310,19 @@<br> }<br> <br> msg = stasis_message_create(ast_bridge_snapshot_type(), snapshot);<br>+ ao2_ref(snapshot, -1);<br> if (!msg) {<br> return;<br> }<br> <br> stasis_publish(ast_bridge_topic(bridge), msg);<br>+ ao2_ref(msg, -1);<br> }<br> <br> static void bridge_publish_state_from_blob(struct ast_bridge *bridge,<br> struct ast_bridge_blob *obj)<br> {<br>- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);<br>+ struct stasis_message *msg;<br> <br> ast_assert(obj != NULL);<br> <br>@@ -326,6 +332,7 @@<br> }<br> <br> stasis_publish(ast_bridge_topic(bridge), msg);<br>+ ao2_ref(msg, -1);<br> }<br> <br> /*! \brief Destructor for bridge merge messages */<br>@@ -342,7 +349,7 @@<br> /*! \brief Bridge merge message creation helper */<br> static struct ast_bridge_merge_message *bridge_merge_message_create(struct ast_bridge *to, struct ast_bridge *from)<br> {<br>- RAII_VAR(struct ast_bridge_merge_message *, msg, NULL, ao2_cleanup);<br>+ struct ast_bridge_merge_message *msg;<br> <br> msg = ao2_alloc(sizeof(*msg), bridge_merge_message_dtor);<br> if (!msg) {<br>@@ -350,16 +357,13 @@<br> }<br> <br> msg->to = ast_bridge_snapshot_create(to);<br>- if (!msg->to) {<br>- return NULL;<br>- }<br>-<br> msg->from = ast_bridge_snapshot_create(from);<br>- if (!msg->from) {<br>+ if (!msg->to || !msg->from) {<br>+ ao2_ref(msg, -1);<br>+<br> return NULL;<br> }<br> <br>- ao2_ref(msg, +1);<br> return msg;<br> }<br> <br>@@ -368,16 +372,17 @@<br> const struct stasis_message_sanitizer *sanitize)<br> {<br> struct ast_bridge_merge_message *merge = stasis_message_data(msg);<br>- RAII_VAR(struct ast_json *, json_bridge_to,<br>- ast_bridge_snapshot_to_json(merge->to, sanitize), ast_json_unref);<br>- RAII_VAR(struct ast_json *, json_bridge_from,<br>- ast_bridge_snapshot_to_json(merge->from, sanitize), ast_json_unref);<br>+ struct ast_json *json_bridge_to = ast_bridge_snapshot_to_json(merge->to, sanitize);<br>+ struct ast_json *json_bridge_from = ast_bridge_snapshot_to_json(merge->from, sanitize);<br> <br> if (!json_bridge_to || !json_bridge_from) {<br>+ ast_json_unref(json_bridge_to);<br>+ ast_json_unref(json_bridge_from);<br>+<br> return NULL;<br> }<br> <br>- return ast_json_pack("{s: s, s: o, s: O, s: O}",<br>+ return ast_json_pack("{s: s, s: o, s: o, s: o}",<br> "type", "BridgeMerged",<br> "timestamp", ast_json_timeval(*stasis_message_timestamp(msg), NULL),<br> "bridge", json_bridge_to,<br>@@ -386,8 +391,8 @@<br> <br> void ast_bridge_publish_merge(struct ast_bridge *to, struct ast_bridge *from)<br> {<br>- RAII_VAR(struct ast_bridge_merge_message *, merge_msg, NULL, ao2_cleanup);<br>- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);<br>+ struct ast_bridge_merge_message *merge_msg;<br>+ struct stasis_message *msg;<br> <br> if (!ast_bridge_merge_message_type()) {<br> return;<br>@@ -404,11 +409,13 @@<br> }<br> <br> msg = stasis_message_create(ast_bridge_merge_message_type(), merge_msg);<br>+ ao2_ref(merge_msg, -1);<br> if (!msg) {<br> return;<br> }<br> <br> stasis_publish(ast_bridge_topic_all(), msg);<br>+ ao2_ref(msg, -1);<br> }<br> <br> static void bridge_blob_dtor(void *obj)<br>@@ -428,8 +435,8 @@<br> struct ast_channel *chan,<br> struct ast_json *blob)<br> {<br>- RAII_VAR(struct ast_bridge_blob *, obj, NULL, ao2_cleanup);<br>- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);<br>+ struct ast_bridge_blob *obj;<br>+ struct stasis_message *msg;<br> <br> if (!message_type) {<br> return NULL;<br>@@ -443,6 +450,8 @@<br> if (bridge) {<br> obj->bridge = ast_bridge_snapshot_create(bridge);<br> if (obj->bridge == NULL) {<br>+ ao2_ref(obj, -1);<br>+<br> return NULL;<br> }<br> }<br>@@ -450,6 +459,8 @@<br> if (chan) {<br> obj->channel = ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan));<br> if (obj->channel == NULL) {<br>+ ao2_ref(obj, -1);<br>+<br> return NULL;<br> }<br> }<br>@@ -459,19 +470,16 @@<br> }<br> <br> msg = stasis_message_create(message_type, obj);<br>- if (!msg) {<br>- return NULL;<br>- }<br>+ ao2_ref(obj, -1);<br> <br>- ao2_ref(msg, +1);<br> return msg;<br> }<br> <br> void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan,<br> struct ast_channel *swap)<br> {<br>- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);<br>- RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);<br>+ struct stasis_message *msg;<br>+ struct ast_json *blob = NULL;<br> <br> if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {<br> return;<br>@@ -485,6 +493,7 @@<br> }<br> <br> msg = ast_bridge_blob_create(ast_channel_entered_bridge_type(), bridge, chan, blob);<br>+ ast_json_unref(blob);<br> if (!msg) {<br> return;<br> }<br>@@ -492,11 +501,12 @@<br> /* enter blob first, then state */<br> stasis_publish(ast_bridge_topic(bridge), msg);<br> bridge_publish_state_from_blob(bridge, stasis_message_data(msg));<br>+ ao2_ref(msg, -1);<br> }<br> <br> void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *chan)<br> {<br>- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);<br>+ struct stasis_message *msg;<br> <br> if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {<br> return;<br>@@ -509,6 +519,7 @@<br> /* state first, then leave blob (opposite of enter, preserves nesting of events) */<br> bridge_publish_state_from_blob(bridge, stasis_message_data(msg));<br> stasis_publish(ast_bridge_topic(bridge), msg);<br>+ ao2_ref(msg, -1);<br> }<br> <br> static struct ast_json *simple_bridge_channel_event(<br>@@ -518,16 +529,17 @@<br> const struct timeval *tv,<br> const struct stasis_message_sanitizer *sanitize)<br> {<br>- RAII_VAR(struct ast_json *, json_bridge,<br>- ast_bridge_snapshot_to_json(bridge_snapshot, sanitize), ast_json_unref);<br>- RAII_VAR(struct ast_json *, json_channel,<br>- ast_channel_snapshot_to_json(channel_snapshot, sanitize), ast_json_unref);<br>+ struct ast_json *json_bridge = ast_bridge_snapshot_to_json(bridge_snapshot, sanitize);<br>+ struct ast_json *json_channel = ast_channel_snapshot_to_json(channel_snapshot, sanitize);<br> <br> if (!json_bridge || !json_channel) {<br>+ ast_json_unref(json_bridge);<br>+ ast_json_unref(json_channel);<br>+<br> return NULL;<br> }<br> <br>- return ast_json_pack("{s: s, s: o, s: O, s: O}",<br>+ return ast_json_pack("{s: s, s: o, s: o, s: o}",<br> "type", type,<br> "timestamp", ast_json_timeval(*tv, NULL),<br> "bridge", json_bridge,<br>@@ -557,9 +569,10 @@<br> static struct ast_json *container_to_json_array(struct ao2_container *items,<br> const struct stasis_message_sanitizer *sanitize)<br> {<br>- RAII_VAR(struct ast_json *, json_items, ast_json_array_create(), ast_json_unref);<br>+ struct ast_json *json_items = ast_json_array_create();<br> char *item;<br> struct ao2_iterator it;<br>+<br> if (!json_items) {<br> return NULL;<br> }<br>@@ -573,12 +586,14 @@<br> if (ast_json_array_append(json_items, ast_json_string_create(item))) {<br> ao2_cleanup(item);<br> ao2_iterator_destroy(&it);<br>+ ast_json_unref(json_items);<br>+<br> return NULL;<br> }<br> }<br> ao2_iterator_destroy(&it);<br> <br>- return ast_json_ref(json_items);<br>+ return json_items;<br> }<br> <br> static const char *capability2str(uint32_t capabilities)<br>@@ -594,7 +609,7 @@<br> const struct ast_bridge_snapshot *snapshot,<br> const struct stasis_message_sanitizer *sanitize)<br> {<br>- RAII_VAR(struct ast_json *, json_bridge, NULL, ast_json_unref);<br>+ struct ast_json *json_bridge;<br> struct ast_json *json_channels;<br> <br> if (snapshot == NULL) {<br>@@ -625,7 +640,7 @@<br> ast_json_string_create(snapshot->video_source_id));<br> }<br> <br>- return ast_json_ref(json_bridge);<br>+ return json_bridge;<br> }<br> <br> /*!<br>@@ -1225,7 +1240,7 @@<br> <br> void ast_bridge_publish_attended_transfer(struct ast_attended_transfer_message *transfer_msg)<br> {<br>- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);<br>+ struct stasis_message *msg;<br> <br> msg = stasis_message_create(ast_attended_transfer_type(), transfer_msg);<br> if (!msg) {<br>@@ -1233,11 +1248,12 @@<br> }<br> <br> stasis_publish(ast_bridge_topic_all(), msg);<br>+ ao2_ref(msg, -1);<br> }<br> <br> struct ast_bridge_snapshot *ast_bridge_snapshot_get_latest(const char *uniqueid)<br> {<br>- RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);<br>+ struct stasis_message *message;<br> struct ast_bridge_snapshot *snapshot;<br> <br> ast_assert(!ast_strlen_zero(uniqueid));<br>@@ -1249,11 +1265,9 @@<br> return NULL;<br> }<br> <br>- snapshot = stasis_message_data(message);<br>- if (!snapshot) {<br>- return NULL;<br>- }<br>- ao2_ref(snapshot, +1);<br>+ snapshot = ao2_bump(stasis_message_data(message));<br>+ ao2_ref(message, -1);<br>+<br> return snapshot;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7920">change 7920</a>. To unsubscribe, 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/7920"/><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-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I0fa7ab05454f183dc4ff10e26d18776d2b0fcf1f </div>
<div style="display:none"> Gerrit-Change-Number: 7920 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>