[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: message search API
From: |
Alain Magloire |
Subject: |
Re: message search API |
Date: |
Fri, 17 Aug 2001 11:19:41 -0400 (EDT) |
>
> Bonjour,
>
> > If you have time can you take a look at
> > mailutils/mailbox2/include/mailutils/*h
>
> I'm also looking at mailutils/mailbox2/*.c :^)
> In header.c both header_aget_value() and header_aget_field_name()
> always return 0, no matter was the corresponding header present
> or not. The similar bug has already been fixed in /mailbox, so I'd propose:
Ok I see your point. But one problem with this is if
header_aget_value() != 0, this mean that an error occured, so
I will have code like this
char *value = NULL;
if (header_aget_value (header, "Subject", &value) == 0) {
// use value.
free (value);
}
// do other stuff.
This is a memory leak, since the code _always_ allocates memory to
value.
If we follow your proposition we have to eliminate the alternative else
branch on the function, which I think is a good thing.
Meaning, on error, no ressource/memory is allocated.
Ok? or the old behaviour of always 0 ?
===================================
int
header_aget_value (header_t header, const char *name, char **pvalue)
{
char *value;
size_t n = 0;
int status = header_get_value (header, name, NULL, 0, &n);
if (status == 0)
{
value = calloc (n + 1, 1);
if (value == NULL)
return MU_ERROR_NO_MEMORY;
header_get_value (header, name, value, n + 1, NULL);
}
else
{
value = malloc (1);
if (value == NULL)
return MU_ERROR_NO_MEMORY;
*value = '\0';
}
*pvalue = value;
return 0;
}
===================================
alain