Bug 4212 - Memory leak in the ads_default_ou_string(...) function (libads/ldap.c)
Memory leak in the ads_default_ou_string(...) function (libads/ldap.c)
Status: RESOLVED FIXED
Product: Samba 3.0
Classification: Unclassified
Component: Domain Control
3.0.23c
Other Windows XP
: P3 normal
: none
Assigned To: Guenther Deschner
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-11-07 13:53 UTC by David
Modified: 2006-11-09 04:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David 2006-11-07 13:53:52 UTC
There is a memory leak in the last for loop of the ads_default_ou_string(...) function in ldap.c.  The code segment that has the leak is c&p below.

http://viewcvs.samba.org/cgi-bin/viewcvs.cgi/branches/SAMBA_3_0_23/source/libads/ldap.c?rev=19528&view=markup

<Original Code>

	ret = SMB_STRDUP(wkn_dn_exp[0]);

	for (i=1; i < new_ln; i++) {
		char *s;
		asprintf(&s, "%s,%s", ret, wkn_dn_exp[i]);
		ret = SMB_STRDUP(s);
		free(s);
	}

<End Original code>

The problem occurs when "new_ln" is greater then 1.  In the for body, the string pointed to by "ret" before the "ret = SMB_STRDUP(s);" call is actually lost before any attempt to release it back to the system.  The string pointed to by "ret" should be freed before "ret = SMB_STRDUP(s)".  The following code segment fixes the leak.

<Fix Code>

        ret = SMB_STRDUP(wkn_dn_exp[0]);

	for (i=1; i < new_ln; i++) {
		char *s;
		asprintf(&s, "%s,%s", ret, wkn_dn_exp[i]);
+               SAFE_FREE(ret);
		ret = SMB_STRDUP(s);
		free(s);
	}

<End Fix Code>
Comment 1 Guenther Deschner 2006-11-09 04:18:59 UTC
Rev. 19646 has that fixed. Thanks for the report.