[PATCH] Fix resource leaks and pointer issues

Jeremy Allison jra at samba.org
Thu Oct 26 23:04:42 UTC 2017


On Thu, Oct 26, 2017 at 01:28:42PM -0700, Jeremy Allison via samba-technical wrote:
> On Thu, Oct 26, 2017 at 07:52:58AM +0200, Andreas Schneider via samba-technical wrote:
> > On Thursday, 26 October 2017 01:08:30 CEST Jeremy Allison via samba-technical 
> > wrote:
> > > On Wed, Oct 25, 2017 at 08:45:02PM +0200, Andreas Schneider wrote:
> > > > Hi,
> > > > 
> > > > I have several additional patches which should also be in the next 4.7
> > > > release. Should I just open one bug for all of them or individual ones?
> > > 
> > > I suggest just one bug - label it "fix resource leaks and pointer issues".
> > 
> > Done, the bug is:
> > 
> > https://bugzilla.samba.org/show_bug.cgi?id=13101
> > 
> > and I've added the bug url to all patches attached.
> 
> Just one note. The change in smbc_getUser() from char *
> to const char * is an external library change, so we'll
> need to update the shared library version number here.
> 
> We might want to leave that change out of the back-ports
> to 4.7.x and 4.6.x to ensure no ABI change.

There's also an issue with the 3rd patch, f needs to be
checked for != stdout before closing.

I pushed the last 3 patches, but you need to re-review
these first 3 before push.

Cheers,

	Jeremy.
-------------- next part --------------
From 4268ffe688754cc65765386c5fed145c23425381 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Wed, 25 Oct 2017 19:22:34 +0200
Subject: [PATCH 1/3] libsmbclient: Use const for the user

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13101

Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
---
 source3/include/libsmbclient.h | 2 +-
 source3/libsmb/libsmb_setget.c | 2 +-
 source3/libsmb/wscript         | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h
index cf67b1d47a4..b41a2924abd 100644
--- a/source3/include/libsmbclient.h
+++ b/source3/include/libsmbclient.h
@@ -491,7 +491,7 @@ smbc_getUser(SMBCCTX *c);
 
 /** Set the username used for making connections */
 void
-smbc_setUser(SMBCCTX *c, char * user);
+smbc_setUser(SMBCCTX *c, const char *user);
 
 /**
  * Get the timeout used for waiting on connections and response data
diff --git a/source3/libsmb/libsmb_setget.c b/source3/libsmb/libsmb_setget.c
index 80ac6739fe8..591cb39c28f 100644
--- a/source3/libsmb/libsmb_setget.c
+++ b/source3/libsmb/libsmb_setget.c
@@ -71,7 +71,7 @@ smbc_getUser(SMBCCTX *c)
 
 /** Set the username used for making connections */
 void
-smbc_setUser(SMBCCTX *c, char * user)
+smbc_setUser(SMBCCTX *c, const char *user)
 {
 	SAFE_FREE(c->user);
 	if (user) {
diff --git a/source3/libsmb/wscript b/source3/libsmb/wscript
index 6d862f71998..15575bcc6ab 100644
--- a/source3/libsmb/wscript
+++ b/source3/libsmb/wscript
@@ -27,5 +27,5 @@ def build(bld):
                        public_headers='../include/libsmbclient.h',
                        abi_directory='ABI',
                        abi_match='smbc_*',
-                       vnum='0.2.3',
+                       vnum='0.3.3',
                        pc_files='smbclient.pc')
-- 
2.15.0.rc2.357.g7e34df9404-goog


From e69e895fdc60456bba88136ec26242fcde699d45 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Wed, 25 Oct 2017 19:23:02 +0200
Subject: [PATCH 2/3] s4:torture: Avoid useless strdup in libsmbclient test

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13101

Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
---
 source4/torture/libsmbclient/libsmbclient.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c
index f6cd8102c4d..16ad35182cd 100644
--- a/source4/torture/libsmbclient/libsmbclient.c
+++ b/source4/torture/libsmbclient/libsmbclient.c
@@ -38,8 +38,8 @@ bool torture_libsmbclient_init_context(struct torture_context *tctx,
 
 	/* yes, libsmbclient API frees the username when freeing the context, so
 	 * have to pass malloced data here */
-	smbc_setUser(ctx, strdup(cli_credentials_get_username(
-			popt_get_cmdline_credentials())));
+	smbc_setUser(ctx,
+		     cli_credentials_get_username(popt_get_cmdline_credentials()));
 
 	*ctx_p = ctx;
 
-- 
2.15.0.rc2.357.g7e34df9404-goog


From 9e40b0dc0444fc4123e04b73bfd96d5057eb5ab6 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Wed, 25 Oct 2017 19:25:20 +0200
Subject: [PATCH 3/3] s4:pyparam: Fix resource leaks on error

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13101

Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
---
 source4/param/pyparam.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c
index 713e608cf1b..f16c2c0b227 100644
--- a/source4/param/pyparam.c
+++ b/source4/param/pyparam.c
@@ -331,6 +331,9 @@ static PyObject *py_lp_dump_a_parameter(PyObject *self, PyObject *args)
 
 	if (!ret) {
 		PyErr_Format(PyExc_RuntimeError, "Parameter %s unknown for section %s", param_name, section_name);
+		if (f != stdout) {
+			fclose(f);
+		}
 		return NULL;
 	}
 
@@ -479,6 +482,9 @@ static PyObject *py_lp_service_dump(PyObject *self, PyObject *args)
 
 	if (!PyObject_TypeCheck(py_default_service, &PyLoadparmService)) {
 		PyErr_SetNone(PyExc_TypeError);
+		if (f != stdout) {
+			fclose(f);
+		}
 		return NULL;
 	}
 
-- 
2.15.0.rc2.357.g7e34df9404-goog



More information about the samba-technical mailing list