[Asterisk-code-review] WIP (asterisk[13])
Sean Bright
asteriskteam at digium.com
Wed Aug 26 09:21:57 CDT 2020
Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14812 )
Change subject: WIP
......................................................................
WIP
Change-Id: Ie8a7db6a0b68f3995b0846bbb733a21909ba44e5
---
M apps/app_voicemail.c
1 file changed, 26 insertions(+), 31 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/12/14812/1
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 742c9c3..24078f8 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -1017,20 +1017,18 @@
int old_new;
int old_old;
char *uniqueid;
- char mailbox[0];
+ char *mailbox;
};
struct mwi_sub_task {
- const char *mailbox;
- const char *context;
- const char *uniqueid;
+ char *mailbox;
+ char *uniqueid;
};
static void mwi_sub_task_dtor(struct mwi_sub_task *mwist)
{
- ast_free((void *) mwist->mailbox);
- ast_free((void *) mwist->context);
- ast_free((void *) mwist->uniqueid);
+ ast_free(mwist->mailbox);
+ ast_free(mwist->uniqueid);
ast_free(mwist);
}
@@ -13364,31 +13362,20 @@
static int handle_subscribe(void *datap)
{
- unsigned int len;
struct mwi_sub *mwi_sub;
struct mwi_sub_task *p = datap;
- size_t context_len;
- len = sizeof(*mwi_sub) + 1;
- if (!ast_strlen_zero(p->mailbox))
- len += strlen(p->mailbox);
-
- context_len = strlen(p->context) + 1; /* Allow for seperator */
- if (!ast_strlen_zero(p->context))
- len += context_len;
-
- if (!(mwi_sub = ast_calloc(1, len)))
+ mwi_sub = ast_calloc(1, sizeof(*mwi_sub));
+ if (!mwi_sub) {
return -1;
-
- mwi_sub->uniqueid = ast_strdup(p->uniqueid);
- if (!ast_strlen_zero(p->mailbox))
- strcpy(mwi_sub->mailbox, p->mailbox);
-
- if (!ast_strlen_zero(p->context)) {
- strcat(mwi_sub->mailbox, "@");
- ast_copy_string(mwi_sub->mailbox, p->context, context_len);
}
+ mwi_sub->uniqueid = p->uniqueid;
+ mwi_sub->mailbox = p->mailbox;
+
+ /* The sub now owns the memory */
+ p->mailbox = p->uniqueid = NULL;
+
AST_RWLIST_WRLOCK(&mwi_subs);
AST_RWLIST_INSERT_TAIL(&mwi_subs, mwi_sub, entry);
AST_RWLIST_UNLOCK(&mwi_subs);
@@ -13418,7 +13405,7 @@
char *context;
char *mailbox;
- mwist = ast_calloc(1, (sizeof(*mwist)));
+ mwist = ast_calloc(1, sizeof(*mwist));
if (!mwist) {
return;
}
@@ -13426,13 +13413,21 @@
/* The topic name is prefixed with "mwi:all/" as this is a pool topic */
topic = stasis_topic_name(change->topic) + 8;
if (separate_mailbox(ast_strdupa(topic), &mailbox, &context)) {
- ast_free(mwist);
+ mwi_sub_task_dtor(mwist);
return;
}
- mwist->mailbox = ast_strdup(mailbox);
- mwist->context = ast_strdup(context);
- mwist->uniqueid = ast_strdup(change->uniqueid);
+ /* separate_mailbox() guarantees a non-NULL, non-empty mailbox and context */
+ if (ast_asprintf(&mwist->mailbox, "%s@%s", mailbox, context) < 0) {
+ mwi_sub_task_dtor(mwist);
+ return;
+ }
+
+ mwist->uniqueid = ast_strdup(change->uniqueid ?: "");
+ if (!mwist->uniqueid) {
+ mwi_sub_task_dtor(mwist);
+ return;
+ }
if (ast_taskprocessor_push(mwi_subscription_tps, handle_subscribe, mwist) < 0) {
mwi_sub_task_dtor(mwist);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14812
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ie8a7db6a0b68f3995b0846bbb733a21909ba44e5
Gerrit-Change-Number: 14812
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200826/13ae13c5/attachment-0001.html>
More information about the asterisk-code-review
mailing list