mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-18 18:58:22 +00:00
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
This commit is contained in:
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user