Hi all:
I read some code of mailbox, there is a function name
mu_mailbox_create_default as follows, i add a comment and a few codes, then
resolve a memory leak, please get me a massage for this.
/* I add comment and a few codes */
/* if ((mail != NULL) && (tmp_mbox == NULL)), then char *p not free, then add
this */
if (p)
free (p);
int
mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail)
{
char *mbox = NULL;
char *tmp_mbox = NULL;
char *p;
int status = 0;
/* Sanity. */
if (pmbox == NULL)
return MU_ERR_OUT_PTR_NULL;
/* Other utilities may not understand GNU mailutils url namespace, so
use FOLDER instead, to not confuse others by using MAIL. */
if (mail == NULL || *mail == '\0')
{
mail = getenv ("FOLDER");
/* Fallback to wellknown environment. */
if (!mail)
mail = getenv ("MAIL");
if (!mail)
{
if ((status = user_mailbox_name (NULL, &tmp_mbox)))
return status;
mail = tmp_mbox;
}
}
p = mu_tilde_expansion (mail, "/", NULL);
if (tmp_mbox)
{
free (tmp_mbox);
tmp_mbox = p;
}
mail = p;
if (!mail)
return ENOMEM;
switch (mail[0])
{
case '%':
status = percent_expand (mail, &mbox);
break;
case '+':
case '=':
status = plus_expand (mail, &mbox);
break;
case '/':
mbox = strdup (mail);
break;
default:
if (!mu_is_proto (mail))
{
tmp_mbox = mu_getcwd();
mbox = malloc (strlen (tmp_mbox) + strlen (mail) + 2);
sprintf (mbox, "%s/%s", tmp_mbox, mail);
}
else
mbox = strdup (mail);
break;
}
if (tmp_mbox)
free (tmp_mbox);
/* if ((mail != NULL) && (tmp_mbox == NULL)), then char *p not free, then add
this */
if (p)
free (p);
if (status)
return status;
status = mu_mailbox_create (pmbox, mbox);
free (mbox);
return status;
_______________________________________________
Bug-mailutils mailing list
[EMAIL PROTECTED]
http://lists.gnu.org/mailman/listinfo/bug-mailutils