<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7769">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">datastore: Add automatic module references.<br><br>Add a reference to the calling module when it is active to protect<br>access to datastore->info. Remove module references done by<br>func_periodic_hook as the datastore now handles it.<br><br>ASTERISK-25128 #close<br><br>Change-Id: I8357a3711e77591d0d1dd8ab4211a7eedd782c89<br>---<br>M funcs/func_periodic_hook.c<br>M include/asterisk/datastore.h<br>M main/datastore.c<br>3 files changed, 17 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/7769/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/funcs/func_periodic_hook.c b/funcs/func_periodic_hook.c<br>index 0ab3d6b..958da97 100644<br>--- a/funcs/func_periodic_hook.c<br>+++ b/funcs/func_periodic_hook.c<br>@@ -137,8 +137,6 @@<br> ast_free(state->context);<br> ast_free(state->exten);<br> ast_free(state);<br>-<br>- ast_module_unref(ast_module_info->self);<br> }<br> <br> static const struct ast_datastore_info hook_datastore = {<br>@@ -305,7 +303,7 @@<br> if (!(datastore = ast_datastore_alloc(&hook_datastore, uid))) {<br> return -1;<br> }<br>- ast_module_ref(ast_module_info->self);<br>+<br> if (!(state = hook_state_alloc(context, exten, interval, hook_id))) {<br> ast_datastore_free(datastore);<br> return -1;<br>diff --git a/include/asterisk/datastore.h b/include/asterisk/datastore.h<br>index 85e9c68..8d6516b 100644<br>--- a/include/asterisk/datastore.h<br>+++ b/include/asterisk/datastore.h<br>@@ -69,6 +69,7 @@<br> const char *uid; /*!< Unique data store identifier */<br> void *data; /*!< Contained data */<br> const struct ast_datastore_info *info; /*!< Data store type information */<br>+ struct ast_module *mod; /*!< Module referenced by this datastore */<br> unsigned int inheritance; /*!< Number of levels this item will continue to be inherited */<br> AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */<br> };<br>@@ -77,13 +78,16 @@<br> * \brief Create a data store object<br> * \param[in] info information describing the data store object<br> * \param[in] uid unique identifer<br>+ * \param[in] mod The module to hold until this datastore is freed.<br> * \param file, line, function<br> * \version 1.6.1 moved here and renamed from ast_channel_datastore_alloc<br> */<br>-struct ast_datastore * attribute_malloc __ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid,<br>- const char *file, int line, const char *function);<br>+struct ast_datastore * attribute_malloc __ast_datastore_alloc(<br>+ const struct ast_datastore_info *info, const char *uid, struct ast_module *mod,<br>+ const char *file, int line, const char *function);<br> <br>-#define ast_datastore_alloc(info, uid) __ast_datastore_alloc(info, uid, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+#define ast_datastore_alloc(info, uid) \<br>+ __ast_datastore_alloc(info, uid, AST_MODULE_SELF, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br> <br> /*!<br> * \brief Free a data store object<br>diff --git a/main/datastore.c b/main/datastore.c<br>index 1170e24..a12bbdf 100644<br>--- a/main/datastore.c<br>+++ b/main/datastore.c<br>@@ -31,12 +31,14 @@<br> #include "asterisk/utils.h"<br> #include "asterisk/astobj2.h"<br> #include "asterisk/uuid.h"<br>+#include "asterisk/module.h"<br> <br> /*! \brief Number of buckets for datastore container */<br> #define DATASTORE_BUCKETS 53<br> <br>-struct ast_datastore *__ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid,<br>- const char *file, int line, const char *function)<br>+struct ast_datastore *__ast_datastore_alloc(<br>+ const struct ast_datastore_info *info, const char *uid, struct ast_module *mod,<br>+ const char *file, int line, const char *function)<br> {<br> struct ast_datastore *datastore = NULL;<br> <br>@@ -50,11 +52,14 @@<br> }<br> <br> datastore->info = info;<br>+ datastore->mod = mod;<br> <br> if (!ast_strlen_zero(uid) && !(datastore->uid = ast_strdup(uid))) {<br> ast_free(datastore);<br> datastore = NULL;<br> }<br>+<br>+ ast_module_ref(mod);<br> <br> return datastore;<br> }<br>@@ -75,6 +80,8 @@<br> datastore->uid = NULL;<br> }<br> <br>+ ast_module_unref(datastore->mod);<br>+<br> /* Finally free memory used by ourselves */<br> ast_free(datastore);<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7769">change 7769</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7769"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I8357a3711e77591d0d1dd8ab4211a7eedd782c89 </div>
<div style="display:none"> Gerrit-Change-Number: 7769 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>