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

Xavier shiningxc at gmail.com
Sat Dec 22 12:03:52 EST 2007


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);
}





More information about the pacman-dev mailing list