[pacman-dev] [PATCH] Add remove counterparts to alpm_option_add_* functions

Dan McGee dpmcgee at gmail.com
Sat Dec 22 13:42:12 EST 2007


On Dec 22, 2007 11:03 AM, Xavier <shiningxc at gmail.com> wrote:
> Allan McRae wrote:
> > Before I resubmit an updated patch with all the functions updated, is
> > this function better?  Specifically, do I free vdata correctly?
> >
> > int SYMEXPORT alpm_option_remove_noupgrade(const char *pkg)
> > {
> >     void *vdata = NULL;
> >     handle->noupgrade = alpm_list_remove(handle->noupgrade, pkg,
> >         _alpm_str_cmp, &vdata);
> >     if(vdata != NULL)
> >     {
> >         FREELIST(vdata);
> >         return 1;
> >     }
> >     return 0;
> > }
> >
> >
>
> If vdata is just a string (not a list), just do :
> free(vdata);
>
> Or you can also do FREE(vdata), which is equivalent to:
> free(vdata); vdata = NULL;
>
> Also, following pacman syntax, it would rather look like :
>
> int SYMEXPORT alpm_option_remove_noupgrade(const char *pkg)
> {
>      void *vdata = NULL;
>      handle->noupgrade = alpm_list_remove(handle->noupgrade, pkg,
>          _alpm_str_cmp, &vdata);
>      if(vdata != NULL) {
>          FREE(vdata);
>          return(1);
>      }
>      return(0);
>
> }

Yep, this looks good, and I don't see any memleaks anymore.

-Dan




More information about the pacman-dev mailing list