Fix bug #8970 - Possible memory leaks in the samba master process.
authorRichard Sharpe <realrichardsharpe@gmail.com>
Thu, 31 May 2012 22:43:14 +0000 (15:43 -0700)
committerKarolin Seeger <kseeger@samba.org>
Wed, 13 Jun 2012 17:35:22 +0000 (19:35 +0200)
Signed-off-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/debug.c
source3/nmbd/nmbd.c
source3/param/loadparm.c
source3/smbd/server.c
source3/winbindd/winbindd.c

index 579fc1b1f60b3acdf2c536ff36590732fae20f37..559a34ebb57e4e8733eca9e59f5e904830a8a1b7 100644 (file)
@@ -3918,9 +3918,9 @@ void expire_workgroups_and_servers(time_t t);
 /* The following definitions come from param/loadparm.c  */
 
 char *lp_smb_ports(void);
-char *lp_dos_charset(void);
-char *lp_unix_charset(void);
-char *lp_display_charset(void);
+const char *lp_dos_charset(void);
+const char *lp_unix_charset(void);
+const char *lp_display_charset(void);
 char *lp_logfile(void);
 char *lp_configfile(void);
 char *lp_smb_passwd_file(void);
index 80b8310ab20bd4482cbb63325a7164bf0aa85a78..05e9eeeaad698753173b862d107948c3b3bfe615 100644 (file)
@@ -657,9 +657,11 @@ bool reopen_logs( void )
                        SAFE_FREE(fname);
                        fname = SMB_STRDUP(logfname);
                        if (!fname) {
+                               TALLOC_FREE(logfname);
                                return false;
                        }
                }
+               TALLOC_FREE(logfname);
        }
 
        debugf = fname;
@@ -1028,6 +1030,8 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
         */
        if( lp_timestamp_logs() || lp_debug_prefix_timestamp() || !(lp_loaded()) ) {
                char header_str[200];
+               char *curtime = current_timestring(talloc_tos(),
+                                       lp_debug_hires_timestamp());
 
                header_str[0] = '\0';
 
@@ -1050,19 +1054,18 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
                                 ", class=%s",
                                 default_classname_table[cls]);
                }
-  
+
                /* Print it all out at once to prevent split syslog output. */
                if( lp_debug_prefix_timestamp() ) {
                    (void)Debug1( "[%s, %2d%s] ",
-                       current_timestring(talloc_tos(),
-                                          lp_debug_hires_timestamp()),
+                       curtime,
                        level, header_str);
                } else {
                    (void)Debug1( "[%s, %2d%s] %s(%s)\n",
-                       current_timestring(talloc_tos(),
-                                          lp_debug_hires_timestamp()),
+                       curtime,
                        level, header_str, location, func );
                }
+               TALLOC_FREE(curtime);
        }
 
        errno = old_errno;
index 48e6d9305458da89cc0be606d6c5d3c29dc1d2f4..2a7b28d97d3337406e2eb3cdf871bc1345a12010 100644 (file)
@@ -366,11 +366,12 @@ static bool reload_nmbd_services(bool test)
        set_remote_machine_name("nmbd", False);
 
        if ( lp_loaded() ) {
-               const char *fname = lp_configfile();
+               char *fname = lp_configfile();
                if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) {
                        set_dyn_CONFIGFILE(fname);
                        test = False;
                }
+               TALLOC_FREE(fname);
        }
 
        if ( test && !lp_file_list_changed() )
index 28ffc08d498647c9462af391c34308a7110aef5c..8c1cf0973b0729ac54c6d14aa1f2e8a0c96b1b85 100644 (file)
@@ -5318,9 +5318,9 @@ static char *lp_string(const char *s)
  char fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
 
 FN_GLOBAL_STRING(lp_smb_ports, &Globals.smb_ports)
-FN_GLOBAL_STRING(lp_dos_charset, &Globals.dos_charset)
-FN_GLOBAL_STRING(lp_unix_charset, &Globals.unix_charset)
-FN_GLOBAL_STRING(lp_display_charset, &Globals.display_charset)
+FN_GLOBAL_CONST_STRING(lp_dos_charset, &Globals.dos_charset)
+FN_GLOBAL_CONST_STRING(lp_unix_charset, &Globals.unix_charset)
+FN_GLOBAL_CONST_STRING(lp_display_charset, &Globals.display_charset)
 FN_GLOBAL_STRING(lp_logfile, &Globals.szLogFile)
 FN_GLOBAL_STRING(lp_configfile, &Globals.szConfigFile)
 FN_GLOBAL_STRING(lp_smb_passwd_file, &Globals.szSMBPasswdFile)
@@ -9283,7 +9283,11 @@ bool lp_load_ex(const char *pszFname,
                }
        }
 
-       lp_add_auto_services(lp_auto_services());
+       {
+               char *serv = lp_auto_services();
+               lp_add_auto_services(serv);
+               TALLOC_FREE(serv);
+       }
 
        if (add_ipc) {
                /* When 'restrict anonymous = 2' guest connections to ipc$
index 201e301c1f0cf01e47ee15a5700d13d03f38d2e3..63a9869dcef367fe653afc8747b138e1f9ee1ae9 100644 (file)
@@ -804,6 +804,7 @@ bool reload_services(bool test)
                        set_dyn_CONFIGFILE(fname);
                        test = False;
                }
+               TALLOC_FREE(fname);
        }
 
        reopen_logs();
index 034e43be04978f7a9ff677c3a4b0b3e8fc41e95a..0550da87d29df216e741a64fee11313682b515bb 100644 (file)
@@ -67,11 +67,12 @@ static bool reload_services_file(const char *lfile)
        bool ret;
 
        if (lp_loaded()) {
-               const char *fname = lp_configfile();
+               char *fname = lp_configfile();
 
                if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) {
                        set_dyn_CONFIGFILE(fname);
                }
+               TALLOC_FREE(fname);
        }
 
        /* if this is a child, restore the logfile to the special