summaryrefslogtreecommitdiffstats
path: root/source3/lib/substitute.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2012-01-26 14:53:43 -0800
committerJeremy Allison <jra@samba.org>2012-01-27 01:26:28 +0100
commit17a77ea9b484a7040098fc66cf78625df4c14c65 (patch)
tree864901d7fec2efa035d98e143d6968dcda04cd00 /source3/lib/substitute.c
parent633a28b276a98628c333b8c8b20dfe30c099caf5 (diff)
downloadsamba-17a77ea9b484a7040098fc66cf78625df4c14c65.tar.gz
samba-17a77ea9b484a7040098fc66cf78625df4c14c65.tar.xz
samba-17a77ea9b484a7040098fc66cf78625df4c14c65.zip
Fix a really slow memory leak (in master at least). Found by Ira Cooper <ira@wakeful.net>.
Bug #8724 - Memory leak in parent smbd on connection. Autobuild-User: Jeremy Allison <jra@samba.org> Autobuild-Date: Fri Jan 27 01:26:28 CET 2012 on sn-devel-104
Diffstat (limited to 'source3/lib/substitute.c')
-rw-r--r--source3/lib/substitute.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c
index eae6d15f7c..5427ed87a2 100644
--- a/source3/lib/substitute.c
+++ b/source3/lib/substitute.c
@@ -195,7 +195,7 @@ void sub_set_smb_name(const char *name)
}
static char sub_peeraddr[INET6_ADDRSTRLEN];
-static const char *sub_peername = "";
+static const char *sub_peername = NULL;
static char sub_sockaddr[INET6_ADDRSTRLEN];
void sub_set_socket_ids(const char *peeraddr, const char *peername,
@@ -208,6 +208,11 @@ void sub_set_socket_ids(const char *peeraddr, const char *peername,
}
strlcpy(sub_peeraddr, addr, sizeof(sub_peeraddr));
+ if (sub_peername != NULL &&
+ sub_peername != sub_peeraddr) {
+ free(discard_const_p(char,sub_peername));
+ sub_peername = NULL;
+ }
sub_peername = SMB_STRDUP(peername);
if (sub_peername == NULL) {
sub_peername = sub_peeraddr;
@@ -547,7 +552,7 @@ static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
break;
case 'M' :
a_string = realloc_string_sub(a_string, "%M",
- sub_peername);
+ sub_peername ? sub_peername : "");
break;
case 'R' :
a_string = realloc_string_sub(a_string, "%R", remote_proto);