summaryrefslogtreecommitdiff
path: root/source4/torture
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-09-28 05:42:02 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:24 -0500
commita675b09e8d45b9298df8f8c82bbaa7b91a793eb5 (patch)
tree48161ba27365850055e8378339aa612360b2d9a8 /source4/torture
parentc0af446d57224fec94f4b0901cee4532dc6835b5 (diff)
downloadsamba-a675b09e8d45b9298df8f8c82bbaa7b91a793eb5.tar.gz
samba-a675b09e8d45b9298df8f8c82bbaa7b91a793eb5.tar.bz2
samba-a675b09e8d45b9298df8f8c82bbaa7b91a793eb5.zip
r2709: finally solved the talloc reference problem.
The problem was that the simple "uint_t ref_count;" in a talloc chunk did not give enough information. It told us that a pointer was referenced more than once, but it didn't say who it was referenced by. This means that when the pointer was freed we had no sane way to clean up the reference. I have now replaced ref_count with a "refs" list, which means that references point to the pointer, and the pointer has a linked list of references. So now we can cleanup from either direction without losing track of anything. I've also added a LOCAL-TALLOC smbtorture test that tests talloc behaviour for some common uses. (This used to be commit 911a8d590cb184bcb892810729955c2c4cf02550)
Diffstat (limited to 'source4/torture')
-rw-r--r--source4/torture/config.mk3
-rw-r--r--source4/torture/local/talloc.c115
-rw-r--r--source4/torture/torture.c17
3 files changed, 126 insertions, 9 deletions
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index 9c7395e572..6403d0c3a7 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -98,7 +98,8 @@ REQUIRED_SUBSYSTEMS = \
# Start SUBSYSTEM TORTURE_LOCAL
[SUBSYSTEM::TORTURE_LOCAL]
ADD_OBJ_FILES = \
- torture/local/iconv.o
+ torture/local/iconv.o \
+ torture/local/talloc.o
REQUIRED_SUBSYSTEMS = \
LIBSMB
# End SUBSYSTEM TORTURE_LOCAL
diff --git a/source4/torture/local/talloc.c b/source4/torture/local/talloc.c
new file mode 100644
index 0000000000..49cdc958b0
--- /dev/null
+++ b/source4/torture/local/talloc.c
@@ -0,0 +1,115 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ local testing of talloc routines.
+
+ Copyright (C) Andrew Tridgell 2004
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+
+/*
+ test references
+*/
+static BOOL test_ref1(void)
+{
+ void *p1, *p2, *ref, *r1;
+
+ printf("TESTING SINGLE REFERENCE FREE\n");
+
+ p1 = talloc_named_const(NULL, 1, "p1");
+ p2 = talloc_named_const(p1, 1, "p2");
+ talloc_named_const(p1, 1, "x1");
+ talloc_named_const(p1, 1, "x2");
+ talloc_named_const(p1, 1, "x3");
+
+ r1 = talloc_named_const(NULL, 1, "r1");
+ ref = talloc_reference(r1, p2);
+ talloc_report_full(NULL, stdout);
+
+ printf("Freeing p2\n");
+ talloc_free(p2);
+ talloc_report_full(NULL, stdout);
+
+ printf("Freeing p1\n");
+ talloc_free(p1);
+ talloc_report_full(NULL, stdout);
+
+ printf("Freeing r1\n");
+ talloc_free(r1);
+ talloc_report_full(NULL, stdout);
+
+ if (talloc_total_size(NULL) != 0) {
+ printf("non-zero total size\n");
+ return False;
+ }
+
+ return True;
+}
+
+/*
+ test references
+*/
+static BOOL test_ref2(void)
+{
+ void *p1, *p2, *ref, *r1;
+
+ printf("TESTING DOUBLE REFERENCE FREE\n");
+
+ p1 = talloc_named_const(NULL, 1, "p1");
+ talloc_named_const(p1, 1, "x1");
+ talloc_named_const(p1, 1, "x2");
+ talloc_named_const(p1, 1, "x3");
+ p2 = talloc_named_const(p1, 1, "p2");
+
+ r1 = talloc_named_const(NULL, 1, "r1");
+ ref = talloc_reference(r1, p2);
+ talloc_report_full(NULL, stdout);
+ printf("Freeing ref\n");
+ talloc_free(ref);
+ talloc_report_full(NULL, stdout);
+ printf("Freeing p2\n");
+ talloc_free(p2);
+ talloc_report_full(NULL, stdout);
+ printf("Freeing p1\n");
+ talloc_free(p1);
+ talloc_report_full(NULL, stdout);
+ printf("Freeing r1\n");
+ talloc_free(r1);
+ talloc_report_full(NULL, stdout);
+
+ if (talloc_total_size(NULL) != 0) {
+ printf("non-zero total size\n");
+ return False;
+ }
+
+ return True;
+}
+
+
+BOOL torture_local_talloc(int dummy)
+{
+ BOOL ret = True;
+
+ init_iconv();
+
+ ret &= test_ref1();
+ ret &= test_ref2();
+
+ return True;
+}
diff --git a/source4/torture/torture.c b/source4/torture/torture.c
index 5db861124b..c6af807357 100644
--- a/source4/torture/torture.c
+++ b/source4/torture/torture.c
@@ -94,10 +94,10 @@ BOOL torture_open_connection_share(struct smbcli_state **c,
flags |= SMBCLI_FULL_CONNECTION_USE_KERBEROS;
status = smbcli_full_connection(c, lp_netbios_name(),
- hostname, NULL,
- sharename, "?????",
- username, username[0]?userdomain:"",
- password, flags, &retry);
+ hostname, NULL,
+ sharename, "?????",
+ username, username[0]?userdomain:"",
+ password, flags, &retry);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to open connection - %s\n", nt_errstr(status));
return False;
@@ -858,10 +858,10 @@ static BOOL run_tcon_devtype_test(int dummy)
const char *password = lp_parm_string(-1, "torture", "password");
status = smbcli_full_connection(&cli1, lp_netbios_name(),
- host, NULL,
- share, "?????",
- username, userdomain,
- password, flags, &retry);
+ host, NULL,
+ share, "?????",
+ username, userdomain,
+ password, flags, &retry);
if (!NT_STATUS_IS_OK(status)) {
printf("could not open connection\n");
@@ -4247,6 +4247,7 @@ static struct {
/* local (no server) testers */
{"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
{"LOCAL-ICONV", torture_local_iconv, 0},
+ {"LOCAL-TALLOC", torture_local_talloc, 0},
/* ldap testers */
{"LDAP-BASIC", torture_ldap_basic, 0},