confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Confuse-devel] bug?


From: Martin Hedenfalk
Subject: Re: [Confuse-devel] bug?
Date: Sun, 30 Mar 2003 17:55:52 +0200

On Sun, 23 Mar 2003 18:58:10 +0100
Freddy <address@hidden> wrote:

> [...]
> 
> In more detail, I have a function called 'conf_refresh', which does
> the re-reading of the config. This fuction defines the cfgopt_t
> type-variables. I use this line for my sections (with those flags you
> wrote):'CFG_SEC("section", section_opts, CFGF_MULTI | CFGF_TITLE)'. Is
> that a problem that these cfgopt_t type-arrays are defined every time
> when I call the funcion conf_refresh? Anyway, I always call cfg_free()
> before I return from the funtion even if one of the functions (e.g.
> cfg_parse) gives back an error so I have to return immediately. I have
> tried to put additional cfg_free()-s in different places as well,
> unfortunately it didn't help..

The cfgopt_t vars must be declared as static within the conf_refresh
function, or as global variables. (Otherwise you'll get a segfault when
libConfuse tries to read the uninitialized memory outside that functions
scope.)

The cfg_free() function should only be called before you re-read the
config file, to free the old values.

Thus the conf_refresh function should look something like this:

void conf_refresh(void)
{
  static cfgopt_t opts[] = {
     ...
  };

  if(cfg)
    /* free all old values */
    cfg_free(cfg);
  cfg = cfg_init(opts, 0);
  cfg_parse(cfg, "filename");
}

HTH / Martin

-- 
Martin Hedenfalk <address@hidden>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]