diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2007-10-27 17:56:59 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2007-10-27 17:56:59 +0200 |
commit | 06e402d71c3b71b2a50a64383c3dbecd6ddba735 (patch) | |
tree | 0341457e8114d8828e0054ff6b58790951cf1706 /nslcd/cfg.c | |
parent | 8a7210593953077047d5515bf7cdc2ff4349b838 (diff) |
make cfg_init() only callable once and add note about not free()ing memory
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@463 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nslcd/cfg.c')
-rw-r--r-- | nslcd/cfg.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/nslcd/cfg.c b/nslcd/cfg.c index e5ba7af..b328efa 100644 --- a/nslcd/cfg.c +++ b/nslcd/cfg.c @@ -691,24 +691,27 @@ static void cfg_read(const char *filename,struct ldap_config *cfg) void cfg_init(const char *fname) { + /* check if we were called before */ + if (nslcd_cfg!=NULL) + { + log_log(LOG_CRIT,"cfg_init() may only be called once"); + exit(EXIT_FAILURE); + } + /* allocate the memory (this memory is not freed anywhere) */ + nslcd_cfg=(struct ldap_config *)malloc(sizeof(struct ldap_config)); if (nslcd_cfg==NULL) { - /* allocate the memory */ - nslcd_cfg=(struct ldap_config *)malloc(sizeof(struct ldap_config)); - if (nslcd_cfg==NULL) - { - log_log(LOG_CRIT,"malloc() failed to allocate memory"); - exit(EXIT_FAILURE); - } - /* clear configuration */ - cfg_defaults(nslcd_cfg); - /* read configfile */ - cfg_read(fname,nslcd_cfg); - /* do some sanity checks */ - if (nslcd_cfg->ldc_uris[0] == NULL) - { - log_log(LOG_ERR,"no URIs defined in config"); - exit(EXIT_FAILURE); - } + log_log(LOG_CRIT,"malloc() failed to allocate memory"); + exit(EXIT_FAILURE); + } + /* clear configuration */ + cfg_defaults(nslcd_cfg); + /* read configfile */ + cfg_read(fname,nslcd_cfg); + /* do some sanity checks */ + if (nslcd_cfg->ldc_uris[0] == NULL) + { + log_log(LOG_ERR,"no URIs defined in config"); + exit(EXIT_FAILURE); } } |