Fix bug 8823 - source3/smbd/process.c:smb_dump seems to have a memory leak.
authorJeremy Allison <jra@samba.org>
Wed, 21 Mar 2012 21:34:34 +0000 (14:34 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 21 Mar 2012 23:20:40 +0000 (00:20 +0100)
Based on code from Richard Sharpe. Move to talloc from malloc.

Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Thu Mar 22 00:20:41 CET 2012 on sn-devel-104

source3/smbd/process.c

index 8b15ac88f991c7ff816559328701529206448823..defedf6d6ce1e66486d28e970bada65be8a552d8 100644 (file)
@@ -1315,12 +1315,17 @@ static void smb_dump(const char *name, int type, const char *data)
 
        len = smb_len_tcp(data)+4;
        for (i=1;i<100;i++) {
-               if (asprintf(&fname, "/tmp/%s.%d.%s", name, i,
-                            type ? "req" : "resp") == -1) {
+               fname = talloc_asprintf(talloc_tos(),
+                               "/tmp/%s.%d.%s",
+                               name,
+                               i,
+                               type ? "req" : "resp");
+               if (fname == NULL) {
                        return;
                }
                fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644);
                if (fd != -1 || errno != EEXIST) break;
+               TALLOC_FREE(fname);
        }
        if (fd != -1) {
                ssize_t ret = write(fd, data, len);
@@ -1329,7 +1334,7 @@ static void smb_dump(const char *name, int type, const char *data)
                close(fd);
                DEBUG(0,("created %s len %lu\n", fname, (unsigned long)len));
        }
-       SAFE_FREE(fname);
+       TALLOC_FREE(fname);
 }
 
 /****************************************************************************