<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7918">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
Jenkins2: Approved for Submit
</div><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;">diff --git a/main/stasis_bridges.c b/main/stasis_bridges.c<br>index 413c9be..0de4197 100644<br>--- a/main/stasis_bridges.c<br>+++ b/main/stasis_bridges.c<br>@@ -235,7 +235,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> snapshot = ao2_alloc_options(sizeof(*snapshot), bridge_snapshot_dtor,<br>@@ -247,17 +247,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>@@ -283,14 +288,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>@@ -304,17 +308,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>@@ -324,6 +330,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>@@ -340,7 +347,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>@@ -348,16 +355,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>@@ -366,16 +370,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>@@ -384,8 +389,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>@@ -400,11 +405,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>@@ -424,8 +431,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>@@ -439,6 +446,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>@@ -446,6 +455,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>@@ -455,19 +466,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 (swap) {<br> blob = ast_json_pack("{s: s}", "swap", ast_channel_uniqueid(swap));<br>@@ -477,6 +485,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>@@ -484,11 +493,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> msg = ast_bridge_blob_create(ast_channel_left_bridge_type(), bridge, chan, NULL);<br> if (!msg) {<br>@@ -498,6 +508,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>@@ -507,16 +518,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>@@ -546,9 +558,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>@@ -562,12 +575,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>@@ -583,7 +598,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>@@ -614,7 +629,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>@@ -1214,7 +1229,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>@@ -1222,11 +1237,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>@@ -1238,11 +1254,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/7918">change 7918</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/7918"/><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: I0fa7ab05454f183dc4ff10e26d18776d2b0fcf1f </div>
<div style="display:none"> Gerrit-Change-Number: 7918 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </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 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>