[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-337-gdb9fa47

Jeremy Allison jra at samba.org
Tue Nov 20 00:42:44 GMT 2007


The branch, v3-2-test has been updated
       via  db9fa472a89eb78a7b1f7cabcf195331c3b448d9 (commit)
      from  a317f70c229f7730279eaa323f7ebfd499257f76 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit db9fa472a89eb78a7b1f7cabcf195331c3b448d9
Author: Volker Lendecke <vl at sernet.de>
Date:   Mon Nov 19 12:36:16 2007 +0100

    Add stackframes to public libsmbclient functions
    
    As we use talloc_tos() in inner libsmbclient/ functions more and more, we need
    to make sure not to create memleaks by not free'ing talloc stackframes. This
    patch wraps all calls in libsmbclient.c that are publically exported into a
    talloc_stackframe()/talloc_free() pair.
    
    Jeremy, Derrell, can you check this?
    
    Thanks,
    
    Volker

-----------------------------------------------------------------------

Summary of changes:
 source/libsmb/libsmbclient.c |  309 +++++++++++++++++++++++++++++++++---------
 1 files changed, 245 insertions(+), 64 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c
index dbc51d1..ee560b6 100644
--- a/source/libsmb/libsmbclient.c
+++ b/source/libsmb/libsmbclient.c
@@ -1060,11 +1060,13 @@ smbc_open_ctx(SMBCCTX *context,
 	SMBCSRV *srv   = NULL;
 	SMBCFILE *file = NULL;
 	int fd;
+	TALLOC_CTX *frame = talloc_stackframe();
 
 	if (!context || !context->internal ||
 	    !context->internal->_initialized) {
 
 		errno = EINVAL;  /* Best I can think of ... */
+		TALLOC_FREE(frame);
 		return NULL;
 
 	}
@@ -1072,6 +1074,7 @@ smbc_open_ctx(SMBCCTX *context,
 	if (!fname) {
 
 		errno = EINVAL;
+		TALLOC_FREE(frame);
 		return NULL;
 
 	}
@@ -1085,6 +1088,7 @@ smbc_open_ctx(SMBCCTX *context,
                             password, sizeof(password),
                             NULL, 0)) {
                 errno = EINVAL;
+		TALLOC_FREE(frame);
                 return NULL;
         }
 
@@ -1096,6 +1100,7 @@ smbc_open_ctx(SMBCCTX *context,
 	if (!srv) {
 
 		if (errno == EPERM) errno = EACCES;
+		TALLOC_FREE(frame);
 		return NULL;  /* smbc_server sets errno */
     
 	}
@@ -1114,6 +1119,7 @@ smbc_open_ctx(SMBCCTX *context,
 		if (!file) {
 
 			errno = ENOMEM;
+			TALLOC_FREE(frame);
 			return NULL;
 
 		}
@@ -1125,6 +1131,7 @@ smbc_open_ctx(SMBCCTX *context,
 		{
 			d_printf("Could not resolve %s\n", path);
 			SAFE_FREE(file);
+			TALLOC_FREE(frame);
 			return NULL;
 		}
 		/*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/
@@ -1136,6 +1143,7 @@ smbc_open_ctx(SMBCCTX *context,
 
 			SAFE_FREE(file);
 			errno = smbc_errno(context, targetcli);
+			TALLOC_FREE(frame);
 			return NULL;
 
 		}
@@ -1176,10 +1184,12 @@ smbc_open_ctx(SMBCCTX *context,
                         if (smbc_lseek_ctx(context, file, 0, SEEK_END) < 0) {
                                 (void) smbc_close_ctx(context, file);
                                 errno = ENXIO;
+				TALLOC_FREE(frame);
                                 return NULL;
                         }
                 }
 
+		TALLOC_FREE(frame);
 		return file;
 
 	}
@@ -1192,11 +1202,13 @@ smbc_open_ctx(SMBCCTX *context,
 		eno = smbc_errno(context, srv->cli);
 		file = (context->opendir)(context, fname);
 		if (!file) errno = eno;
+		TALLOC_FREE(frame);
 		return file;
 
 	}
 
 	errno = EINVAL; /* FIXME, correct errno ? */
+	TALLOC_FREE(frame);
 	return NULL;
 
 }
@@ -1238,6 +1250,7 @@ smbc_read_ctx(SMBCCTX *context,
 	fstring server, share, user, password;
 	pstring path, targetpath;
 	struct cli_state *targetcli;
+	TALLOC_CTX *frame = talloc_stackframe();
 
         /*
          * offset:
@@ -1254,6 +1267,7 @@ smbc_read_ctx(SMBCCTX *context,
 	    !context->internal->_initialized) {
 
 		errno = EINVAL;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1263,6 +1277,7 @@ smbc_read_ctx(SMBCCTX *context,
 	if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
 
 		errno = EBADF;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1274,6 +1289,7 @@ smbc_read_ctx(SMBCCTX *context,
 	if (buf == NULL) {
 
 		errno = EINVAL;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1288,6 +1304,7 @@ smbc_read_ctx(SMBCCTX *context,
                             password, sizeof(password),
                             NULL, 0)) {
                 errno = EINVAL;
+		TALLOC_FREE(frame);
                 return -1;
         }
 	
@@ -1296,6 +1313,7 @@ smbc_read_ctx(SMBCCTX *context,
                               &targetcli, targetpath))
 	{
 		d_printf("Could not resolve %s\n", path);
+		TALLOC_FREE(frame);
 		return -1;
 	}
 	/*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/
@@ -1305,6 +1323,7 @@ smbc_read_ctx(SMBCCTX *context,
 	if (ret < 0) {
 
 		errno = smbc_errno(context, targetcli);
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1313,6 +1332,7 @@ smbc_read_ctx(SMBCCTX *context,
 
 	DEBUG(4, ("  --> %d\n", ret));
 
+	TALLOC_FREE(frame);
 	return ret;  /* Success, ret bytes of data ... */
 
 }
@@ -1332,6 +1352,7 @@ smbc_write_ctx(SMBCCTX *context,
 	fstring server, share, user, password;
 	pstring path, targetpath;
 	struct cli_state *targetcli;
+	TALLOC_CTX *frame = talloc_stackframe();
 
 	/* First check all pointers before dereferencing them */
 	
@@ -1339,6 +1360,7 @@ smbc_write_ctx(SMBCCTX *context,
 	    !context->internal->_initialized) {
 
 		errno = EINVAL;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1346,6 +1368,7 @@ smbc_write_ctx(SMBCCTX *context,
 	if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
 
 		errno = EBADF;
+		TALLOC_FREE(frame);
 		return -1;
     
 	}
@@ -1355,6 +1378,7 @@ smbc_write_ctx(SMBCCTX *context,
 	if (buf == NULL) {
 
 		errno = EINVAL;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1371,6 +1395,7 @@ smbc_write_ctx(SMBCCTX *context,
                             password, sizeof(password),
                             NULL, 0)) {
                 errno = EINVAL;
+		TALLOC_FREE(frame);
                 return -1;
         }
 	
@@ -1379,6 +1404,7 @@ smbc_write_ctx(SMBCCTX *context,
                               &targetcli, targetpath))
 	{
 		d_printf("Could not resolve %s\n", path);
+		TALLOC_FREE(frame);
 		return -1;
 	}
 	/*d_printf(">>>write: resolved path as %s\n", targetpath);*/
@@ -1389,12 +1415,14 @@ smbc_write_ctx(SMBCCTX *context,
 	if (ret <= 0) {
 
 		errno = smbc_errno(context, targetcli);
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
 
 	file->offset += ret;
 
+	TALLOC_FREE(frame);
 	return ret;  /* Success, 0 bytes of data ... */
 }
  
@@ -1410,11 +1438,13 @@ smbc_close_ctx(SMBCCTX *context,
 	fstring server, share, user, password;
 	pstring path, targetpath;
 	struct cli_state *targetcli;
+	TALLOC_CTX *frame = talloc_stackframe();
 
 	if (!context || !context->internal ||
 	    !context->internal->_initialized) {
 
 		errno = EINVAL;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1422,6 +1452,7 @@ smbc_close_ctx(SMBCCTX *context,
 	if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
    
 		errno = EBADF;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1429,6 +1460,7 @@ smbc_close_ctx(SMBCCTX *context,
 	/* IS a dir ... */
 	if (!file->file) {
 		
+		TALLOC_FREE(frame);
 		return (context->closedir)(context, file);
 
 	}
@@ -1443,6 +1475,7 @@ smbc_close_ctx(SMBCCTX *context,
                             password, sizeof(password),
                             NULL, 0)) {
                 errno = EINVAL;
+		TALLOC_FREE(frame);
                 return -1;
         }
 	
@@ -1451,6 +1484,7 @@ smbc_close_ctx(SMBCCTX *context,
                               &targetcli, targetpath))
 	{
 		d_printf("Could not resolve %s\n", path);
+		TALLOC_FREE(frame);
 		return -1;
 	}
 	/*d_printf(">>>close: resolved path as %s\n", targetpath);*/
@@ -1467,7 +1501,7 @@ smbc_close_ctx(SMBCCTX *context,
 		SAFE_FREE(file->fname);
 		SAFE_FREE(file);
 		(context->callbacks.remove_unused_server_fn)(context, srv);
-
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1475,6 +1509,7 @@ smbc_close_ctx(SMBCCTX *context,
 	DLIST_REMOVE(context->internal->_files, file);
 	SAFE_FREE(file->fname);
 	SAFE_FREE(file);
+	TALLOC_FREE(frame);
 
 	return 0;
 }
@@ -1499,11 +1534,13 @@ smbc_getatr(SMBCCTX * context,
 	pstring targetpath;
 	struct cli_state *targetcli;
 	time_t write_time;
+	TALLOC_CTX *frame = talloc_stackframe();
 
 	if (!context || !context->internal ||
 	    !context->internal->_initialized) {
  
 		errno = EINVAL;
+		TALLOC_FREE(frame);
  		return -1;
  
  	}
@@ -1522,6 +1559,7 @@ smbc_getatr(SMBCCTX * context,
 	if (!cli_resolve_path( "", srv->cli, fixedpath, &targetcli, targetpath))
 	{
 		d_printf("Couldn't resolve %s\n", path);
+		TALLOC_FREE(frame);
 		return False;
 	}
 	
@@ -1532,12 +1570,14 @@ smbc_getatr(SMBCCTX * context,
                            write_time_ts,
                            change_time_ts,
                            size, mode, ino)) {
-            return True;
+		TALLOC_FREE(frame);
+		return True;
         }
 
 	/* if this is NT then don't bother with the getatr */
 	if (targetcli->capabilities & CAP_NT_SMBS) {
                 errno = EPERM;
+		TALLOC_FREE(frame);
                 return False;
         }
 
@@ -1564,10 +1604,12 @@ smbc_getatr(SMBCCTX * context,
                 }
 
 		srv->no_pathinfo2 = True;
+		TALLOC_FREE(frame);
 		return True;
 	}
 
         errno = EPERM;
+	TALLOC_FREE(frame);
 	return False;
 
 }
@@ -1592,6 +1634,7 @@ smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
 {
         int fd;
         int ret;
+	TALLOC_CTX *frame = talloc_stackframe();
 
         /*
          * First, try setpathinfo (if qpathinfo succeeded), for it is the
@@ -1624,6 +1667,7 @@ smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
                 if ((fd = cli_open(srv->cli, path, O_RDWR, DENY_NONE)) < 0) {
 
                         errno = smbc_errno(context, srv->cli);
+			TALLOC_FREE(frame);
                         return -1;
                 }
 
@@ -1648,10 +1692,12 @@ smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
 
                 if (! ret) {
                         errno = smbc_errno(context, srv->cli);
+			TALLOC_FREE(frame);
                         return False;
                 }
         }
 
+	TALLOC_FREE(frame);
         return True;
 }
 
@@ -1667,11 +1713,13 @@ smbc_unlink_ctx(SMBCCTX *context,
 	pstring path, targetpath;
 	struct cli_state *targetcli;
 	SMBCSRV *srv = NULL;
+	TALLOC_CTX *frame = talloc_stackframe();
 
 	if (!context || !context->internal ||
 	    !context->internal->_initialized) {
 
 		errno = EINVAL;  /* Best I can think of ... */
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1679,6 +1727,7 @@ smbc_unlink_ctx(SMBCCTX *context,
 	if (!fname) {
 
 		errno = EINVAL;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1692,6 +1741,7 @@ smbc_unlink_ctx(SMBCCTX *context,
                             password, sizeof(password),
                             NULL, 0)) {
                 errno = EINVAL;
+		TALLOC_FREE(frame);
                 return -1;
         }
 
@@ -1702,6 +1752,7 @@ smbc_unlink_ctx(SMBCCTX *context,
 
 	if (!srv) {
 
+		TALLOC_FREE(frame);
 		return -1;  /* smbc_server sets errno */
 
 	}
@@ -1710,6 +1761,7 @@ smbc_unlink_ctx(SMBCCTX *context,
 	if (!cli_resolve_path( "", srv->cli, path, &targetcli, targetpath))
 	{
 		d_printf("Could not resolve %s\n", path);
+		TALLOC_FREE(frame);
 		return -1;
 	}
 	/*d_printf(">>>unlink: resolved path as %s\n", targetpath);*/
@@ -1738,6 +1790,7 @@ smbc_unlink_ctx(SMBCCTX *context,
 				/* Hmmm, bad error ... What? */
 
 				errno = smbc_errno(context, targetcli);
+				TALLOC_FREE(frame);
 				return -1;
 
 			}
@@ -1751,10 +1804,12 @@ smbc_unlink_ctx(SMBCCTX *context,
 			}
 		}
 
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
 
+	TALLOC_FREE(frame);
 	return 0;  /* Success ... */
 
 }
@@ -1785,6 +1840,7 @@ smbc_rename_ctx(SMBCCTX *ocontext,
 	struct cli_state *targetcli1;
         struct cli_state *targetcli2;
 	SMBCSRV *srv = NULL;
+	TALLOC_CTX *frame = talloc_stackframe();
 
 	if (!ocontext || !ncontext || 
 	    !ocontext->internal || !ncontext->internal ||
@@ -1792,6 +1848,7 @@ smbc_rename_ctx(SMBCCTX *ocontext,
 	    !ncontext->internal->_initialized) {
 
 		errno = EINVAL;  /* Best I can think of ... */
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1799,6 +1856,7 @@ smbc_rename_ctx(SMBCCTX *ocontext,
 	if (!oname || !nname) {
 
 		errno = EINVAL;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1833,6 +1891,7 @@ smbc_rename_ctx(SMBCCTX *ocontext,
 		/* Can't rename across file systems, or users?? */
 
 		errno = EXDEV;
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1841,6 +1900,7 @@ smbc_rename_ctx(SMBCCTX *ocontext,
                           server1, share1, workgroup, user1, password1);
 	if (!srv) {
 
+		TALLOC_FREE(frame);
 		return -1;
 
 	}
@@ -1849,6 +1909,7 @@ smbc_rename_ctx(SMBCCTX *ocontext,
 	if (!cli_resolve_path( "", srv->cli, path1, &targetcli1, targetpath1))
 	{
 		d_printf("Could not resolve %s\n", path1);
+		TALLOC_FREE(frame);
 		return -1;
 	}
 	/*d_printf(">>>rename: resolved path as %s\n", targetpath1);*/
@@ -1856,6 +1917,7 @@ smbc_rename_ctx(SMBCCTX *ocontext,
 	if (!cli_resolve_path( "", srv->cli, path2, &targetcli2, targetpath2))
 	{
 		d_printf("Could not resolve %s\n", path2);
+		TALLOC_FREE(frame);
 		return -1;
 	}
 	/*d_printf(">>>rename: resolved path as %s\n", targetpath2);*/
@@ -1866,6 +1928,7 @@ smbc_rename_ctx(SMBCCTX *ocontext,
 		/* can't rename across file systems */
 		
 		errno = EXDEV;
+		TALLOC_FREE(frame);
 		return -1;
 	}
 
@@ -1877,13 +1940,14 @@ smbc_rename_ctx(SMBCCTX *ocontext,
 		    !cli_rename(targetcli1, targetpath1, targetpath2)) {
 
 			errno = eno;
+			TALLOC_FREE(frame);
 			return -1;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list