Hi Andrew,

On Sat, 2014-04-26 at 07:56PM -0400, Andrew Gregory wrote:
> Signed-off-by: Andrew Gregory <[email protected]>
> ---
>  src/pacman/conf.c | 88 
> +++++++++++++++++++++++++++++--------------------------
>  src/pacman/conf.h |  9 ++++++
>  2 files changed, 55 insertions(+), 42 deletions(-)
> 
> diff --git a/src/pacman/conf.c b/src/pacman/conf.c
> index f75f3a7..bcfa12a 100644
> --- a/src/pacman/conf.c
> +++ b/src/pacman/conf.c
> @@ -151,6 +151,16 @@ int config_free(config_t *oldconfig)
>       return 0;
>  }
>  
> +void config_repo_free(config_repo_t *repo)
> +{
> +     if(repo == NULL) {
> +             return;
> +     }
> +     free(repo->name);
> +     FREELIST(repo->servers);
> +     free(repo);
> +}
> +
>  /** Helper function for download_with_xfercommand() */
>  static char *get_filename(const char *url)
>  {
> @@ -750,14 +760,10 @@ static int setup_libalpm(void)
>   * calling library methods.
>   */
>  struct section_t {
> -     /* useful for all sections */
>       const char *name;
> +     config_repo_t *repo;

I haven't looked into the details, but might it make sense to just have
the struct here and not a pointer to a struct?

[...]
>  static int _parse_directive(const char *file, int linenum, const char *name,
> @@ -904,13 +902,21 @@ static int _parse_directive(const char *file, int 
> linenum, const char *name,
>  {
>       struct section_t *section = data;
>       if(!key && !value) {
> -             int ret = finish_section(section);
> -             pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
> +             int ret = finish_section(data);
>               section->name = name;
> -             if(name && strcmp(name, "options") == 0) {
> +             pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
> +             config_repo_free(section->repo);
> +             section->repo = NULL;
> +             section->is_options = 0;
> +             if(!name) {
> +                     /* end of file, do nothing */
> +             } else if(strcmp(name, "options") == 0) {
>                       section->is_options = 1;
> -             } else {
> -                     section->is_options = 0;
> +             } else if(!section->parse_options) {
> +                     section->repo = calloc(sizeof(config_repo_t), 1);

The return value of calloc needs to be checked to be non NULL.

        Sören

Reply via email to