From fae01b48994fd3168fd921af68dab1b4003adc49 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Mar 2007 01:17:36 +0000 Subject: r21608: Fix a couple of memleaks in error code paths before Coverity finds them :-) Jeremy. (This used to be commit cbe725f1b09f3d0edbdf823e0862edf21e16d336) --- source3/utils/net_ads.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_ads.c') diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index cb5b08c672..b1ac40fd72 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -1819,7 +1819,7 @@ static int net_ads_printer_publish(int argc, const char **argv) TALLOC_CTX *mem_ctx = talloc_init("net_ads_printer_publish"); ADS_MODLIST mods = ads_init_mods(mem_ctx); char *prt_dn, *srv_dn, **srv_cn; - char *srv_cn_escaped, *printername_escaped; + char *srv_cn_escaped = NULL, *printername_escaped = NULL; LDAPMessage *res = NULL; if (!ADS_ERR_OK(ads_startup(True, &ads))) { @@ -1874,6 +1874,8 @@ static int net_ads_printer_publish(int argc, const char **argv) srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn[0]); printername_escaped = escape_rdn_val_string_alloc(printername); if (!srv_cn_escaped || !printername_escaped) { + SAFE_FREE(srv_cn_escaped); + SAFE_FREE(printername_escaped); d_fprintf(stderr, "Internal error, out of memory!"); ads_destroy(&ads); return -1; @@ -1881,16 +1883,21 @@ static int net_ads_printer_publish(int argc, const char **argv) asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, printername_escaped, srv_dn); + SAFE_FREE(srv_cn_escaped); + SAFE_FREE(printername_escaped); + pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SPOOLSS, &nt_status); if (!pipe_hnd) { d_fprintf(stderr, "Unable to open a connnection to the spoolss pipe on %s\n", servername); + SAFE_FREE(prt_dn); ads_destroy(&ads); return -1; } if (!W_ERROR_IS_OK(get_remote_printer_publishing_data(pipe_hnd, mem_ctx, &mods, printername))) { + SAFE_FREE(prt_dn); ads_destroy(&ads); return -1; } @@ -1898,11 +1905,13 @@ static int net_ads_printer_publish(int argc, const char **argv) rc = ads_add_printer_entry(ads, prt_dn, mem_ctx, &mods); if (!ADS_ERR_OK(rc)) { d_fprintf(stderr, "ads_publish_printer: %s\n", ads_errstr(rc)); + SAFE_FREE(prt_dn); ads_destroy(&ads); return -1; } d_printf("published printer\n"); + SAFE_FREE(prt_dn); ads_destroy(&ads); return 0; -- cgit