[pacman-dev] [PATCH] Fix several memleaks, mostly related to errors handling.

Xavier shiningxc at gmail.com
Mon Nov 26 17:07:45 EST 2007


On Mon, Nov 26, 2007 at 03:49:14PM -0600, Aaron Griffin wrote:
> On Nov 24, 2007 5:02 AM, Xavier <shiningxc at gmail.com> wrote:
> > That's the first thing I thought about, but I don't know if that is possible.
> > There are two lists that can only be freed after the error happens : *data
> > and deps (asked could be freed before).
> > Or maybe it is possible to do something like :
> > MALLOC(miss, sizeof(pmdepmissing_t), FREELIST(*data);  FREELIST(deps);
> >   RET_ERR(PM_ERR_MEMORY, -1));
> >
> > Though, there is also the "goto cleanup;" that would be skipped, and so the
> > "alpm_list_free(list);", so that's yet another call to add there.
> > So that would duplicate the "FREELIST(deps)'" and "alpm_list_free(list);"
> > calls.
> 
> While this one has already been merged, you could still use the macro
> by simply throwing something like (void)0 in the third param. Or even
> pm_errno = BLAHBLAH.
> This way we still get the output from the macro, even if we don't get
> the real failure+return.
> 

I see, but how do we detect if it failed or not? Using 0, it doesn't seem to
be possible. Maybe by setting pm_errno as you said, or ret.

So maybe something like this :

MALLOC(miss, sizeof(pmdepmissing_t), ret = -1);
if(ret == -1) {
	/* free the lists */
	pm_errno = blabla;
	goto cleanup;
}

?

I don't know how MACRO handle arguments, so I wasn't sure this was possible.




More information about the pacman-dev mailing list