From 3bea01f01d76e1e95a8239c0d3f67073992136a1 Mon Sep 17 00:00:00 2001 From: Jan Zeleny Date: Wed, 14 Dec 2011 07:20:11 -0500 Subject: Don't give memory context in confdb where not needed --- src/confdb/confdb.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'src/confdb/confdb.c') diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c index 57023f29..04f02b5c 100644 --- a/src/confdb/confdb.c +++ b/src/confdb/confdb.c @@ -337,15 +337,22 @@ failed: return ret; } -int confdb_get_int(struct confdb_ctx *cdb, TALLOC_CTX *ctx, +int confdb_get_int(struct confdb_ctx *cdb, const char *section, const char *attribute, int defval, int *result) { char **values = NULL; long val; int ret; + TALLOC_CTX *tmp_ctx; - ret = confdb_get_param(cdb, ctx, section, attribute, &values); + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + ret = ENOMEM; + goto failed; + } + + ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values); if (ret != EOK) { goto failed; } @@ -373,27 +380,34 @@ int confdb_get_int(struct confdb_ctx *cdb, TALLOC_CTX *ctx, val = defval; } - talloc_free(values); + talloc_free(tmp_ctx); *result = (int)val; return EOK; failed: - talloc_free(values); + talloc_free(tmp_ctx); DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n", attribute, section, ret, strerror(ret))); return ret; } -long confdb_get_long(struct confdb_ctx *cdb, TALLOC_CTX *ctx, +long confdb_get_long(struct confdb_ctx *cdb, const char *section, const char *attribute, long defval, long *result) { char **values = NULL; long val; int ret; + TALLOC_CTX *tmp_ctx; - ret = confdb_get_param(cdb, ctx, section, attribute, &values); + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + ret = ENOMEM; + goto failed; + } + + ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values); if (ret != EOK) { goto failed; } @@ -416,27 +430,34 @@ long confdb_get_long(struct confdb_ctx *cdb, TALLOC_CTX *ctx, val = defval; } - talloc_free(values); + talloc_free(tmp_ctx); *result = val; return EOK; failed: - talloc_free(values); + talloc_free(tmp_ctx); DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n", attribute, section, ret, strerror(ret))); return ret; } -int confdb_get_bool(struct confdb_ctx *cdb, TALLOC_CTX *ctx, +int confdb_get_bool(struct confdb_ctx *cdb, const char *section, const char *attribute, bool defval, bool *result) { char **values = NULL; bool val; int ret; + TALLOC_CTX *tmp_ctx; - ret = confdb_get_param(cdb, ctx, section, attribute, &values); + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + ret = ENOMEM; + goto failed; + } + + ret = confdb_get_param(cdb, tmp_ctx, section, attribute, &values); if (ret != EOK) { goto failed; } @@ -465,13 +486,13 @@ int confdb_get_bool(struct confdb_ctx *cdb, TALLOC_CTX *ctx, val = defval; } - talloc_free(values); + talloc_free(tmp_ctx); *result = val; return EOK; failed: - talloc_free(values); + talloc_free(tmp_ctx); DEBUG(1, ("Failed to read [%s] from [%s], error [%d] (%s)\n", attribute, section, ret, strerror(ret))); return ret; -- cgit