From 9fee03365621cca011da4521d98f1e1aa2882278 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 20 Sep 2010 06:03:58 +0200 Subject: s3:services_db: rewrite svcctl_lookup_description() to use a tmp talloc ctx Also remove a possible memory by tallocing the result string also in a default case, where a string constant was returned before. --- source3/services/services_db.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index f0b7dd0cac..b223e9acf2 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -677,40 +677,39 @@ const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, struct char *path = NULL; WERROR wresult; DATA_BLOB blob; + TALLOC_CTX *mem_ctx = talloc_stackframe(); - /* now add the security descriptor */ - - if (asprintf(&path, "%s\\%s", KEY_SERVICES, name) < 0) { + path = talloc_asprintf(mem_ctx, "%s\\%s", KEY_SERVICES, name); + if (path == NULL) { return NULL; } - wresult = regkey_open_internal( NULL, &key, path, token, + + wresult = regkey_open_internal(mem_ctx, &key, path, token, REG_KEY_READ ); - if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("svcctl_lookup_description: key lookup failed! [%s] (%s)\n", - path, win_errstr(wresult))); - SAFE_FREE(path); - return NULL; + if (!W_ERROR_IS_OK(wresult)) { + DEBUG(0, ("svcctl_lookup_description: key lookup failed! " + "[%s] (%s)\n", path, win_errstr(wresult))); + goto done; } - SAFE_FREE(path); wresult = regval_ctr_init(key, &values); if (!W_ERROR_IS_OK(wresult)) { - DEBUG(0,("svcctl_lookup_description: talloc() failed!\n")); - TALLOC_FREE( key ); - return NULL; + DEBUG(0, ("svcctl_lookup_description: talloc() failed!\n")); + goto done; } fetch_reg_values( key, values ); if ( !(val = regval_ctr_getvalue( values, "Description" )) ) { - TALLOC_FREE( key ); - return "Unix Service"; + description = talloc_strdup(ctx, "Unix Service"); + goto done; } blob = data_blob_const(regval_data_p(val), regval_size(val)); pull_reg_sz(ctx, &blob, &description); - TALLOC_FREE(key); +done: + talloc_free(mem_ctx); return description; } -- cgit