]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
func_periodic_hook: move module ref
authorRussell Bryant <russell@russellbryant.com>
Sat, 12 Apr 2014 01:35:34 +0000 (01:35 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 12 Apr 2014 01:35:34 +0000 (01:35 +0000)
The previous code left one error path where the module would be unref'd twice
instead of once.  It was done once in the error handling block, and again inside
of datastore destruction.

Now the module ref is only released in the datastore destructor and only acquired
when the datastore has been successfully allocated.

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

funcs/func_periodic_hook.c

index 1f6f3aea98828c274dfd6bcde5567ca3475045d8..661ebcbed147b29db3f8318413bf01a1ea2222b2 100644 (file)
@@ -300,13 +300,11 @@ static int init_hook(struct ast_channel *chan, const char *context, const char *
 
        snprintf(uid, sizeof(uid), "%u", hook_id);
 
-       ast_module_ref(ast_module_info->self);
        if (!(datastore = ast_datastore_alloc(&hook_datastore, uid))) {
-               ast_module_unref(ast_module_info->self);
                return -1;
        }
+       ast_module_ref(ast_module_info->self);
        if (!(state = hook_state_alloc(context, exten, interval, hook_id))) {
-               ast_module_unref(ast_module_info->self);
                ast_datastore_free(datastore);
                return -1;
        }