Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nslcd/cfg.c
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2007-10-27 17:56:59 +0200
committerArthur de Jong <arthur@arthurdejong.org>2007-10-27 17:56:59 +0200
commit06e402d71c3b71b2a50a64383c3dbecd6ddba735 (patch)
tree0341457e8114d8828e0054ff6b58790951cf1706 /nslcd/cfg.c
parent8a7210593953077047d5515bf7cdc2ff4349b838 (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.c37
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);
}
}