From 06e402d71c3b71b2a50a64383c3dbecd6ddba735 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sat, 27 Oct 2007 15:56:59 +0000 Subject: 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 --- nslcd/cfg.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'nslcd/cfg.c') 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); } } -- cgit v1.2.3