summaryrefslogtreecommitdiff
path: root/main/datastore.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2017-12-29 15:50:12 -0500
committerCorey Farrell <git@cfware.com>2017-12-29 16:16:11 -0500
commit0fe7df641aa0e23b8400d32b935de4834ee4f182 (patch)
tree74e162d10c8b00645d2da5b9b62b1f629c7eeee9 /main/datastore.c
parent80e6b2eff54a4ff57e2521164224b1b1c878ae94 (diff)
datastore: Add automatic module references.
Add a reference to the calling module when it is active to protect access to datastore->info. Remove module references done by func_periodic_hook as the datastore now handles it. ASTERISK-25128 #close Change-Id: I8357a3711e77591d0d1dd8ab4211a7eedd782c89
Diffstat (limited to 'main/datastore.c')
-rw-r--r--main/datastore.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/main/datastore.c b/main/datastore.c
index 1170e24f8..a12bbdf34 100644
--- a/main/datastore.c
+++ b/main/datastore.c
@@ -31,12 +31,14 @@
#include "asterisk/utils.h"
#include "asterisk/astobj2.h"
#include "asterisk/uuid.h"
+#include "asterisk/module.h"
/*! \brief Number of buckets for datastore container */
#define DATASTORE_BUCKETS 53
-struct ast_datastore *__ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid,
- const char *file, int line, const char *function)
+struct ast_datastore *__ast_datastore_alloc(
+ const struct ast_datastore_info *info, const char *uid, struct ast_module *mod,
+ const char *file, int line, const char *function)
{
struct ast_datastore *datastore = NULL;
@@ -50,12 +52,15 @@ struct ast_datastore *__ast_datastore_alloc(const struct ast_datastore_info *inf
}
datastore->info = info;
+ datastore->mod = mod;
if (!ast_strlen_zero(uid) && !(datastore->uid = ast_strdup(uid))) {
ast_free(datastore);
datastore = NULL;
}
+ ast_module_ref(mod);
+
return datastore;
}
@@ -75,6 +80,8 @@ int ast_datastore_free(struct ast_datastore *datastore)
datastore->uid = NULL;
}
+ ast_module_unref(datastore->mod);
+
/* Finally free memory used by ourselves */
ast_free(datastore);