Eliminate some more unnecessary RAII_VAR() uses.
authorRichard Mudgett <rmudgett@digium.com>
Tue, 15 Apr 2014 18:30:24 +0000 (18:30 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Tue, 15 Apr 2014 18:30:24 +0000 (18:30 +0000)
RAII_VAR() is not a hammer appropriate to pound all nails.
........

Merged revisions 412413 from http://svn.asterisk.org/svn/asterisk/branches/12

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@412414 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/features_config.c
main/rtp_engine.c
main/stasis_channels.c
res/res_parking.c

index d58886e..ca0ee77 100644 (file)
@@ -1081,7 +1081,8 @@ static struct ast_datastore *get_feature_chan_ds(struct ast_channel *chan)
 
        if (!(ds = ast_channel_datastore_find(chan, &feature_ds_info, NULL))) {
                /* Hasn't been created yet.  Trigger creation. */
-               RAII_VAR(struct features_config *, cfg, get_feature_ds(chan), ao2_cleanup);
+               ao2_cleanup(get_feature_ds(chan));
+
                ds = ast_channel_datastore_find(chan, &feature_ds_info, NULL);
        }
 
index 4837230..e47ab83 100644 (file)
@@ -1915,28 +1915,22 @@ void ast_rtp_publish_rtcp_message(struct ast_rtp_instance *rtp,
                struct ast_rtp_rtcp_report *report,
                struct ast_json *blob)
 {
-       RAII_VAR(struct rtcp_message_payload *, payload,
-                       ao2_alloc(sizeof(*payload), rtcp_message_payload_dtor), ao2_cleanup);
-       RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+       RAII_VAR(struct rtcp_message_payload *, payload, NULL, ao2_cleanup);
        RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 
+       payload = ao2_alloc(sizeof(*payload), rtcp_message_payload_dtor);
        if (!payload || !report) {
                return;
        }
 
        if (!ast_strlen_zero(rtp->channel_uniqueid)) {
-               snapshot = ast_channel_snapshot_get_latest(rtp->channel_uniqueid);
-               if (snapshot) {
-                       ao2_ref(snapshot, +1);
-               }
+               payload->snapshot = ast_channel_snapshot_get_latest(rtp->channel_uniqueid);
        }
-
        if (blob) {
+               payload->blob = blob;
                ast_json_ref(blob);
        }
-       ao2_ref(report, 1);
-       payload->snapshot = snapshot;
-       payload->blob = blob;
+       ao2_ref(report, +1);
        payload->report = report;
 
        message = stasis_message_create(message_type, payload);
index c75d174..eefb7a9 100644 (file)
@@ -172,8 +172,8 @@ static void channel_snapshot_dtor(void *obj)
 
 struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan)
 {
-       RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+       struct ast_channel_snapshot *snapshot;
+       struct ast_bridge *bridge;
        char nativeformats[256];
        struct ast_str *write_transpath = ast_str_alloca(256);
        struct ast_str *read_transpath = ast_str_alloca(256);
@@ -187,6 +187,7 @@ struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *cha
 
        snapshot = ao2_alloc(sizeof(*snapshot), channel_snapshot_dtor);
        if (!snapshot || ast_string_field_init(snapshot, 1024)) {
+               ao2_cleanup(snapshot);
                return NULL;
        }
 
@@ -231,6 +232,7 @@ struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *cha
 
        if ((bridge = ast_channel_get_bridge(chan))) {
                ast_string_field_set(snapshot, bridgeid, bridge->uniqueid);
+               ao2_cleanup(bridge);
        }
 
        ast_string_field_set(snapshot, nativeformats, ast_getformatname_multiple(nativeformats, sizeof(nativeformats),
@@ -267,7 +269,6 @@ struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *cha
        snapshot->channel_vars = ast_channel_get_vars(chan);
        snapshot->tech_properties = ast_channel_tech(chan)->properties;
 
-       ao2_ref(snapshot, +1);
        return snapshot;
 }
 
index c36d558..c60fdd6 100644 (file)
@@ -890,11 +890,10 @@ static void generate_or_link_lots_to_configs(void)
        struct parking_lot_cfg *lot_cfg;
        struct ao2_iterator iter;
 
-       for (iter = ao2_iterator_init(cfg->parking_lots, 0); (lot_cfg = ao2_iterator_next(&iter)); ao2_ref(lot_cfg, -1)) {
-               RAII_VAR(struct parking_lot *, lot, NULL, ao2_cleanup);
-               lot = parking_lot_build_or_update(lot_cfg, 0);
+       iter = ao2_iterator_init(cfg->parking_lots, 0);
+       for (; (lot_cfg = ao2_iterator_next(&iter)); ao2_ref(lot_cfg, -1)) {
+               ao2_cleanup(parking_lot_build_or_update(lot_cfg, 0));
        }
-
        ao2_iterator_destroy(&iter);
 }