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 +++++++++++++++++++++++++++++++++------------ src/confdb/confdb.h | 4 ++-- 2 files changed, 35 insertions(+), 14 deletions(-) (limited to 'src/confdb') diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c index 57023f299..04f02b5cc 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; diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h index 819e8ff31..18484f023 100644 --- a/src/confdb/confdb.h +++ b/src/confdb/confdb.h @@ -343,7 +343,7 @@ int confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx, * @return ERANGE - The value stored in the ConfDB was outside the range * [INT_MIN..INT_MAX] */ -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); @@ -372,7 +372,7 @@ int confdb_get_int(struct confdb_ctx *cdb, TALLOC_CTX *ctx, * single-valued, or the value was not a boolean. * @return EIO - An I/O error occurred while communicating with the ConfDB */ -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); -- cgit