gpo: don't leak cache_path onto talloc tos
[samba.git] / source3 / utils / net_ads_gpo.c
index 79793b834da543d5fdf90001b645194b23d81e17..8b789e5191493b54f6110255f4fd368f4046b910 100644 (file)
@@ -39,6 +39,7 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
        struct GROUP_POLICY_OBJECT *gpo;
        NTSTATUS result;
        struct security_token *token = NULL;
+       char *gpo_cache_path;
 
        if (argc < 1 || c->display_usage) {
                d_printf("%s\n%s\n%s",
@@ -99,10 +100,17 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
        d_printf(_("finished\n"));
 
        d_printf(_("* Refreshing Group Policy Data "));
-       if (!NT_STATUS_IS_OK(result = check_refresh_gpo_list(ads, mem_ctx,
-                                                            cache_path(GPO_CACHE_DIR),
-                                                            flags,
-                                                            gpo_list))) {
+       gpo_cache_path = cache_path(GPO_CACHE_DIR);
+       if (gpo_cache_path == NULL) {
+               d_printf(_("failed: %s\n"), nt_errstr(NT_STATUS_NO_MEMORY));
+               goto out;
+       }
+       result = check_refresh_gpo_list(ads, mem_ctx,
+                                       gpo_cache_path,
+                                       flags,
+                                       gpo_list);
+       TALLOC_FREE(gpo_cache_path);
+       if (!NT_STATUS_IS_OK(result)) {
                d_printf(_("failed: %s\n"), nt_errstr(result));
                goto out;
        }