summaryrefslogtreecommitdiff
path: root/lib/talloc/testsuite.c
AgeCommit message (Collapse)AuthorFilesLines
2025-01-02replace direct calls to memset_s() with commonly used macrosMichael Tokarev1-1/+1
samba provides macros for zeroing various structures in memory, and all code uses them instead of relying on memset_s(). However, a few places use memset_s() directly. Replace these usages with macros for consistency and to be able to replace memset_s() easier. A few notes. Commit 03a50d8f7d872b6ef701d12 "lib:util: Check memset_s() error code in talloc_keep_secret_destructor()" (Aug-2022) added a check for error return from memset_s(). This is the only place in whole codebase which bothers about doing this. But I've difficult time figuring out the intention. Was there a real case when this code path is actually executed? Commit 7658c9bf0a9c99e3f200571 "lib:crypto: Remove redundant array zeroing" (Nov-2023) removed the OTHER line from the two lines used to zero memory in here. Initially the code used both memset_s() *and* ZERO_ARRAY_LEN(), the former has been removed. This change removes the other - memset_s(), reintroducing ZERO_ARRAY_LEN(). Here however, it's probably better to use BURN_PTR instead of ZERO_ARRAY - in this place and a few lines above. Commit 8dddea2ceda40f2365bd6b1 "lib:talloc: Use memset_s() to avoid the call gets optimized out" (Feb-2024) is a recent commit which introduces memset_s(). However, it does not seem like it makes any difference whatsoever for a testsuite, or that it actually needs to clean up the memory to begin with. We've quite an assortment of all this memory zeroing stuff. Also it is repeated in replace.h and memory.h (two sets in these files are different but has big intersection). I'd say, to fix this mess, things from replace.h should be removed in favour of memory.h, and necessary includes added, but this is for the next time. We also have lots of direct usages of memset_s() in heimdal code. Cc: Joseph Sutton <josephsutton@catalyst.net.nz> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
2024-09-28lib:talloc: Use tabs to align output in speed testAndreas Schneider1-5/+5
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
2024-09-28lib:talloc: Increase alloc size to 128 kilobytesAndreas Schneider1-16/+20
We want to avoid that the optimizer will use stack allocations. This way the test should be a bit more realistic. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
2024-09-28lib:talloc: Don't optimize the speed testAndreas Schneider1-0/+9
If the speed test gets optimized, the malloc() and free() might be replaced by stack allocations. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
2024-09-28lib:talloc: Add talloc_zero vs calloc testAndreas Schneider1-0/+39
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
2024-09-28lib:talloc: Use memset_s() to avoid the call gets optimized outAndreas Schneider1-1/+1
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
2024-09-28lib:talloc: Remove trailing spaces from testsuite.cAndreas Schneider1-31/+31
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
2020-11-10lib: talloc: Remove the ALWAYS_REALLOC code paths.talloc-2.3.2Jeremy Allison1-8/+0
This is now never set, and also never tested, and only makes the talloc code more complicated. Once this is gone we can start looking at the memlimit stuff. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Alexander Bokovoy <ab@samba.org>
2020-11-09lib: talloc: More tests for realloc when used with memlimited poolsArran Cudbard-Bell1-0/+103
This requires the previous patch. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14540 Signed-off-by: Arran Cudbard-Bell <a.cudbardb@freeradius.org> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-11-09lib: talloc: Add more debugging text for existing memlimit + pool testsArran Cudbard-Bell1-0/+14
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14540 Signed-off-by: Arran Cudbard-Bell <a.cudbardb@freeradius.org> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-09-01Spelling fixes s/recieved/received/Mathieu Parent1-2/+2
Signed-off-by: Mathieu Parent <math.parent@gmail.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-21talloc: ASAN fix for test_magic_protectionSwen Schillig1-0/+2
Direct leak of 1152 byte(s) in 1 object(s) allocated from: #0 0x7f06393dfc08 in __interceptor_malloc (/lib64/libasan.so.5+0xefc08) #1 0x7f06392cfd59 in __talloc_with_prefix ../../talloc.c:782 #2 0x7f06392cfd59 in _talloc_pool ../../talloc.c:837 #3 0x7f06392cfd59 in talloc_pool ../../talloc.c:859 #4 0x40b83c in test_magic_protection ../../testsuite.c:1960 #5 0x40b83c in torture_local_talloc ../../testsuite.c:2164 #6 0x402603 in main ../../testsuite_main.c:32 #7 0x7f063908a412 in __libc_start_main (/lib64/libc.so.6+0x24412) Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Matthias Dieter Wallnöfer <mdw@samba.org>
2019-08-21talloc: ASAN fix for test_rustySwen Schillig1-1/+3
Direct leak of 100 byte(s) in 1 object(s) allocated from: #0 0x7f06393dfc08 in __interceptor_malloc (/lib64/libasan.so.5+0xefc08) #1 0x7f06392d1af3 in __talloc_with_prefix ../../talloc.c:782 #2 0x7f06392d1af3 in __talloc ../../talloc.c:824 #3 0x7f06392d1af3 in __talloc_strlendup ../../talloc.c:2455 #4 0x7f06392d1af3 in talloc_strdup ../../talloc.c:2471 #5 0x40b4f0 in test_rusty ../../testsuite.c:1543 #6 0x40b4f0 in torture_local_talloc ../../testsuite.c:2146 #7 0x402603 in main ../../testsuite_main.c:32 #8 0x7f063908a412 in __libc_start_main (/lib64/libc.so.6+0x24412) Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Matthias Dieter Wallnöfer <mdw@samba.org>
2019-08-21talloc: ASAN fix for test_pool_nestSwen Schillig1-0/+2
Direct leak of 96 byte(s) in 1 object(s) allocated from: #0 0x7f06393dfc08 in __interceptor_malloc (/lib64/libasan.so.5+0xefc08) #1 0x7f06392d0c45 in __talloc_with_prefix ../../talloc.c:782 #2 0x7f06392d0c45 in __talloc ../../talloc.c:824 #3 0x7f06392d0c45 in _talloc_named_const ../../talloc.c:981 #4 0x7f06392d0c45 in talloc_named_const ../../talloc.c:1748 #5 0x40901e in test_pool_nest ../../testsuite.c:1451 #6 0x40901e in torture_local_talloc ../../testsuite.c:2096 #7 0x402603 in main ../../testsuite_main.c:32 #8 0x7f063908a412 in __libc_start_main (/lib64/libc.so.6+0x24412) Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Matthias Dieter Wallnöfer <mdw@samba.org>
2019-08-21talloc: ASAN fix for test_talloc_free_in_destructorSwen Schillig1-0/+2
Indirect leak of 104 byte(s) in 1 object(s) allocated from: #0 0x7f06393dfc08 in __interceptor_malloc (/lib64/libasan.so.5+0xefc08) #1 0x7f06392d0c45 in __talloc_with_prefix ../../talloc.c:782 #2 0x7f06392d0c45 in __talloc ../../talloc.c:824 #3 0x7f06392d0c45 in _talloc_named_const ../../talloc.c:981 #4 0x7f06392d0c45 in talloc_named_const ../../talloc.c:1748 #5 0x409edd in test_talloc_free_in_destructor ../../testsuite.c:1256 #6 0x409edd in torture_local_talloc ../../testsuite.c:2138 #7 0x402603 in main ../../testsuite_main.c:32 #8 0x7f063908a412 in __libc_start_main (/lib64/libc.so.6+0x24412) Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Matthias Dieter Wallnöfer <mdw@samba.org>
2019-08-21talloc: ASAN fix for test_realloc_on_destructor_parentSwen Schillig1-0/+2
Direct leak of 96 byte(s) in 1 object(s) allocated from: #0 0x7fd52c00dc08 in __interceptor_malloc (/lib64/libasan.so.5+0xefc08) #1 0x7fd52befec45 in __talloc_with_prefix ../../talloc.c:782 #2 0x7fd52befec45 in __talloc ../../talloc.c:824 #3 0x7fd52befec45 in _talloc_named_const ../../talloc.c:981 #4 0x7fd52befec45 in talloc_named_const ../../talloc.c:1748 #5 0x4099bd in test_realloc_on_destructor_parent ../../testsuite.c:1000 #6 0x4099bd in torture_local_talloc ../../testsuite.c:2129 #7 0x402603 in main ../../testsuite_main.c:32 #8 0x7fd52bcb8412 in __libc_start_main (/lib64/libc.so.6+0x24412) Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Matthias Dieter Wallnöfer <mdw@samba.org>
2019-05-09talloc torture: avoid NULL dereferenceDouglas Bagnall1-1/+3
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2018-01-12talloc: Add tests to require use-after-free to give the correct ↵Andrew Bartlett1-0/+68
talloc_abort() string BUG: https://bugzilla.samba.org/show_bug.cgi?id=13210 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2016-12-13talloc: Add tests for talloc destructor behaviour after talloc_realloc()Andrew Bartlett1-1/+66
That this behaved correctly was not clear, so I added tests to prove it to myself. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Tue Dec 13 06:47:58 CET 2016 on sn-devel-144
2016-12-01talloc: Add tests for talloc_parent() after realloc() of the parentAndrew Bartlett1-4/+13
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2016-10-15talloc: Fix CID 1373619 Unchecked return valueVolker Lendecke1-3/+4
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Sat Oct 15 01:28:02 CEST 2016 on sn-devel-144
2016-10-14talloc: Fix CID 1373621 Unchecked return valueVolker Lendecke1-2/+10
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2016-07-03lib: talloc: Add check for destructor protection.Andrew Bartlett1-0/+6
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2016-06-01talloc: rename local timeval function copiesRalph Boehme1-12/+12
timeval_current() and timeval_elapsed() are public functions from libsamba-util. Redeclaring them as static functions here triggers linker error when building with gcc link-time-optimisation (LTO). This shows the error after reverting this patch: [slow@kazak lto]$ make -j WAF_MAKE=1 python ./buildtools/bin/waf build Waf: Entering directory `/home/slow/git/samba/lto/bin' Selected embedded Heimdal build [ 174/4259] Generating ctdb-samba-version-header [ 174/4259] Generating ctdb-samba-version-header [ 521/4259] Generating source4/torture/local/proto.h [2565/4259] Compiling lib/talloc/testsuite.c [4125/4259] Linking default/source4/torture/smbtorture /tmp/ccvL9UCe.ltrans3.ltrans.o:<artificial>:function smbsrv_accept.lto_priv.11: error: undefined reference to 'timeval_current.lto_priv.630' /tmp/ccvL9UCe.ltrans4.ltrans.o:<artificial>:function smbsrv_recv_smb2_request: error: undefined reference to 'timeval_current.lto_priv.630' /tmp/ccvL9UCe.ltrans4.ltrans.o:<artificial>:function smb2srv_negprot_backend: error: undefined reference to 'timeval_current.lto_priv.630' /tmp/ccvL9UCe.ltrans4.ltrans.o:<artificial>:function smb2srv_negprot_backend: error: undefined reference to 'timeval_current.lto_priv.630' /tmp/ccvL9UCe.ltrans9.ltrans.o:<artificial>:function test_smb2_oplock_batch22: error: undefined reference to 'timeval_elapsed.lto_priv.628' /tmp/ccvL9UCe.ltrans9.ltrans.o:<artificial>:function test_smb2_bench_oplock: error: undefined reference to 'timeval_elapsed.lto_priv.628' /tmp/ccvL9UCe.ltrans9.ltrans.o:<artificial>:function test_smb2_bench_oplock: error: undefined reference to 'timeval_elapsed.lto_priv.628' /tmp/ccvL9UCe.ltrans9.ltrans.o:<artificial>:function test_smb2_bench_oplock: error: undefined reference to 'timeval_elapsed.lto_priv.628' collect2: error: ld returned 1 exit status ... Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Wed Jun 1 21:09:16 CEST 2016 on sn-devel-144
2016-04-26talloc/testsuite: Fix CID 1291641 - Logically dead codeRobin Hack1-5/+5
Add check for snprintf return code. Signed-off-by: Robin Hack <hack.robin@gmail.com> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2015-10-12talloc: Fix the O3 developer buildVolker Lendecke1-2/+5
Compilers can't see that the child exits. Thus "exit_status" is used uninitialized in the child. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2015-10-09talloc: Test magic protection measures.Adrian Cochrane1-0/+66
Signed-off-by: Adrian Cochrane <adrianc@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-08-06lib/talloc: Fix CID 1291639 Missing unlockAnoop C S1-0/+1
Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2015-08-06lib/talloc: Fix CID 1291640 Missing unlockAnoop C S1-0/+1
Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2015-03-17lib: talloc: tests - add test_pthread_talloc_passing() testing talloc in a ↵Jeremy Allison1-0/+153
pthread environment. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo <simo@samba.org> Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Mar 17 19:23:29 CET 2015 on sn-devel-104
2015-03-08lib: talloc: Test suite for the new destructor reparent logic.Jeremy Allison1-0/+82
Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ira Cooper <ira@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Sun Mar 8 20:52:43 CET 2015 on sn-devel-104
2014-05-16talloc/tests: avoid some unused variable warningsStefan Metzmacher1-0/+13
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2013-09-08talloc: Test the pooled objecttalloc-2.1.0Volker Lendecke1-0/+36
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2013-09-08talloc: Allow nested pools.Volker Lendecke1-0/+26
Signed-off-by: Volker Lendecke <vl@samba.org> Signed-off-by: Jeremy Allison <jra@samba.org>
2013-08-27Add simple limited pool tests to test_memlimit().Jeremy Allison1-0/+27
Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
2012-10-05Add tests for talloc_memlimitSimo Sorce1-0/+172
Autobuild-User(master): Simo Sorce <idra@samba.org> Autobuild-Date(master): Fri Oct 5 07:36:38 CEST 2012 on sn-devel-104
2012-07-18talloc: use a struct for pool headers.Rusty Russell1-1/+1
This neatens the code a bit (we should do a similar thing for all the TALLOC_CHUNK macros). Two subtler changes: (1) As a result of the struct, we actually pack object_count into the talloc header on 32-bit platforms (since the header is 40 bytes, but needs to be 16-byte aligned). (2) I avoid VALGRIND_MAKE_MEM_UNDEFINED on memmove when we resize the only entry in a pool; that's done later anyway. With -O2 on my 11.04 Ubuntu 32-bit x86 laptop, the talloc_pool speed as measured by testsuite.c actually increases 10%. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2012-01-10talloc/testsuite: fix compiler warningsStefan Metzmacher1-1/+2
metze Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Tue Jan 10 13:31:33 CET 2012 on sn-devel-104
2011-10-22talloc/testsuite: remove #if _SAMBA_BUILD_==3Stefan Metzmacher1-9/+0
We don't include "includes.h" anymore... metze
2011-08-04talloc: check block count aftter references testAndrew Tridgell1-0/+1
Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
2011-07-29talloc: added test suite for talloc_free_children()Andrew Tridgell1-0/+44
this tests the fix from Simo Autobuild-User: Andrew Tridgell <tridge@samba.org> Autobuild-Date: Fri Jul 29 11:30:13 CEST 2011 on sn-devel-104
2011-05-17talloc: test talloc_steal out of a talloc_poolStefan Metzmacher1-0/+69
metze Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Tue May 17 09:43:01 CEST 2011 on sn-devel-104
2011-05-17talloc: add memset() calls to test_pool()Stefan Metzmacher1-0/+17
This way we the pool based valgrind code. metze
2011-04-08talloc/testsuite: avoid memory leak reported by valgrindStefan Metzmacher1-1/+1
metze Signed-off-By: Andrew Tridgell <tridge@samba.org> Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Fri Apr 8 10:15:41 CEST 2011 on sn-devel-104
2011-04-08talloc/testsuite: test more talloc_pool related thingsStefan Metzmacher1-0/+55
metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-01-05talloc: added a test for the use after free Rusty foundAndrew Tridgell1-0/+17
2011-01-03talloc: Fix warnings in test codeBrad Hards1-1/+4
This should not change any behaviour - the intent is just to reduce the "nuisance" warnings. Signed-off-by: Stefan Metzmacher <metze@samba.org> Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Mon Jan 3 11:12:39 CET 2011 on sn-devel-104
2010-04-20talloc: there is no ambiguity when freeing a ptr with a null parentAndrew Tridgell1-0/+33
when a ptr has a single reference and a NULL parent, then talloc_free(ptr) is not ambiguous, as the caller could not have done a talloc_free(NULL) to free the memory Pair-Programmed-With: Rusty Russell <rusty@samba.org>
2010-03-29talloc: testsuite should use <talloc.h> not "talloc.h"Andrew Tridgell1-1/+1
if we are using the system talloc, the testsuite needs to use the system talloc.h
2009-09-20talloc: fixed talloc_disable_null_tracking()Andrew Tridgell1-1/+2
When we disable null tracking, we need to move any existing objects that are under the null_context to be parented by the true NULL context. We also need a new talloc_enable_null_tracking_no_autofree() function, as the talloc testsuite cannot cope with the moving of the autofree context under the null_context as it wants to check exact counts of objects under the null_context, and smbtorture has a large number of objects in the autofree_context from .init functions