summaryrefslogtreecommitdiffstats
path: root/mutt_idna.c
diff options
context:
space:
mode:
authorAndrew W. Nosenko <awn@bcs.zp.ua>2003-03-18 14:51:00 +0000
committerAndrew W. Nosenko <awn@bcs.zp.ua>2003-03-18 14:51:00 +0000
commit54b897113be2ba8822aab8a9c9d5d0d6c1bfe05b (patch)
treecbf54260adb718d2d748c44fd6996c7845c218c0 /mutt_idna.c
parent350a638cc02884a3f477e49bbd90efe5b7d77fdf (diff)
(mutt_addr_for_display): Fix memory leak. `user' and `domain'
buffers was never deallocated. (mbox_to_udomain): Fix memory leak. `scratch' buffer was not deallocated when `mbx' doesn't contain '@'. Also rewritten for allocating memory only when needed and only how many as needed.
Diffstat (limited to 'mutt_idna.c')
-rw-r--r--mutt_idna.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/mutt_idna.c b/mutt_idna.c
index 34487c40..fc3aec5f 100644
--- a/mutt_idna.c
+++ b/mutt_idna.c
@@ -120,16 +120,16 @@ int mutt_local_to_idna (const char *in, char **out)
static int mbox_to_udomain (const char *mbx, char **user, char **domain)
{
- char *scratch = safe_strdup (mbx);
+ char *p;
*user = NULL;
*domain = NULL;
- if ((*domain = strchr (scratch, '@')) == NULL)
+ p = strchr (mbx, '@');
+ if (!p)
return -1;
-
- **domain = '\0';
- *domain = safe_strdup (*domain + 1);
- *user = scratch;
+ *user = safe_malloc((p - mbx + 1) * sizeof(mbx[0]));
+ strfcpy (*user, mbx, (p - mbx + 1));
+ *domain = safe_strdup(p + 1);
return 0;
}
@@ -203,7 +203,10 @@ const char *mutt_addr_for_display (ADDRESS *a)
{
static char *buff = NULL;
char *tmp = NULL;
- char *domain, *user;
+ /* user and domain will be either allocated or reseted to the NULL in
+ * the mbox_to_udomain(), but for safety... */
+ char *domain = NULL;
+ char *user = NULL;
FREE (&buff);
@@ -211,6 +214,8 @@ const char *mutt_addr_for_display (ADDRESS *a)
return a->mailbox;
if (mutt_idna_to_local (domain, &tmp, MI_MAY_BE_IRREVERSIBLE) != 0)
{
+ FREE (&user);
+ FREE (&domain);
FREE (&tmp);
return a->mailbox;
}
@@ -218,6 +223,8 @@ const char *mutt_addr_for_display (ADDRESS *a)
safe_realloc ((void **) &buff, mutt_strlen (tmp) + mutt_strlen (user) + 2);
sprintf (buff, "%s@%s", NONULL(user), NONULL(tmp)); /* __SPRINTF_CHECKED__ */
FREE (&tmp);
+ FREE (&user);
+ FREE (&domain);
return buff;
}