]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
stasis_cache_pattern: Remove silly usage of RAII_VAR.
authorCorey Farrell <git@cfware.com>
Tue, 9 Jan 2018 17:09:08 +0000 (12:09 -0500)
committerCorey Farrell <git@cfware.com>
Tue, 9 Jan 2018 17:09:08 +0000 (12:09 -0500)
Change-Id: Ic98a51f555062cd863b6db3f8d76065943a9dea3

main/stasis_cache_pattern.c

index 3106cb33e14234a1ced1bdd8a32b7a1ff461913a..2a2ea44e5efda3cc9b3b4e12a13fa871800b3ffc 100644 (file)
@@ -67,8 +67,8 @@ static void all_dtor(void *obj)
 struct stasis_cp_all *stasis_cp_all_create(const char *name,
        snapshot_get_id id_fn)
 {
-       RAII_VAR(char *, cached_name, NULL, ast_free);
-       RAII_VAR(struct stasis_cp_all *, all, NULL, ao2_cleanup);
+       char *cached_name = NULL;
+       struct stasis_cp_all *all;
 
        all = ao2_t_alloc(sizeof(*all), all_dtor, name);
        if (!all) {
@@ -77,21 +77,25 @@ struct stasis_cp_all *stasis_cp_all_create(const char *name,
 
        ast_asprintf(&cached_name, "%s-cached", name);
        if (!cached_name) {
+               ao2_ref(all, -1);
+
                return NULL;
        }
 
        all->topic = stasis_topic_create(name);
        all->topic_cached = stasis_topic_create(cached_name);
+       ast_free(cached_name);
        all->cache = stasis_cache_create(id_fn);
        all->forward_all_to_cached =
                stasis_forward_all(all->topic, all->topic_cached);
 
        if (!all->topic || !all->topic_cached || !all->cache ||
                !all->forward_all_to_cached) {
+               ao2_ref(all, -1);
+
                return NULL;
        }
 
-       ao2_ref(all, +1);
        return all;
 }
 
@@ -136,7 +140,7 @@ static void one_dtor(void *obj)
 struct stasis_cp_single *stasis_cp_single_create(struct stasis_cp_all *all,
        const char *name)
 {
-       RAII_VAR(struct stasis_cp_single *, one, NULL, ao2_cleanup);
+       struct stasis_cp_single *one;
 
        one = stasis_cp_sink_create(all, name);
        if (!one) {
@@ -144,23 +148,22 @@ struct stasis_cp_single *stasis_cp_single_create(struct stasis_cp_all *all,
        }
 
        one->forward_topic_to_all = stasis_forward_all(one->topic, all->topic);
-       if (!one->forward_topic_to_all) {
-               return NULL;
-       }
        one->forward_cached_to_all = stasis_forward_all(
                stasis_caching_get_topic(one->topic_cached), all->topic_cached);
-       if (!one->forward_cached_to_all) {
+
+       if (!one->forward_topic_to_all || !one->forward_cached_to_all) {
+               ao2_ref(one, -1);
+
                return NULL;
        }
 
-       ao2_ref(one, +1);
        return one;
 }
 
 struct stasis_cp_single *stasis_cp_sink_create(struct stasis_cp_all *all,
        const char *name)
 {
-       RAII_VAR(struct stasis_cp_single *, one, NULL, ao2_cleanup);
+       struct stasis_cp_single *one;
 
        one = ao2_t_alloc(sizeof(*one), one_dtor, name);
        if (!one) {
@@ -169,14 +172,18 @@ struct stasis_cp_single *stasis_cp_sink_create(struct stasis_cp_all *all,
 
        one->topic = stasis_topic_create(name);
        if (!one->topic) {
+               ao2_ref(one, -1);
+
                return NULL;
        }
+
        one->topic_cached = stasis_caching_topic_create(one->topic, all->cache);
        if (!one->topic_cached) {
+               ao2_ref(one, -1);
+
                return NULL;
        }
 
-       ao2_ref(one, +1);
        return one;
 }