summaryrefslogtreecommitdiff
path: root/source3/services
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2010-09-20 06:03:58 +0200
committerMichael Adam <obnox@samba.org>2010-09-21 06:53:31 +0200
commit9fee03365621cca011da4521d98f1e1aa2882278 (patch)
tree3be5d1af8213cd35fbe2181be8f215b80fde7306 /source3/services
parent464515cd610b5ee3862d8bc8558cd698d4f7258e (diff)
downloadsamba-9fee03365621cca011da4521d98f1e1aa2882278.tar.gz
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.
Diffstat (limited to 'source3/services')
-rw-r--r--source3/services/services_db.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/source3/services/services_db.c b/source3/services/services_db.c
index f0b7dd0cac9..b223e9acf23 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;
}