1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00
Commit Graph

61 Commits

Author SHA1 Message Date
Rusty Russell
4f331872bc talloc: don't allow a talloc_pool inside a talloc_pool.
We explicitly call free() on a pool which falls to zero, assuming it's
not inside another pool (we crash).  Check on creation and explicitly
document this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2012-07-18 04:54:31 +09:30
Rusty Russell
8893215aaf talloc: use a struct for pool headers.
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-07-18 04:53:31 +09:30
Volker Lendecke
8d5e6770f4 talloc: Fix copy&paste errors 2012-04-24 13:28:44 +02:00
Volker Lendecke
ad3c0e03e2 talloc: Slightly simplify talloc_unlink
Nested if's are hard to understand to me.

Signed-off-by: Stefan Metzmacher <metze@samba.org>

Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Mon Jan  2 19:07:23 CET 2012 on sn-devel-104
2012-01-02 19:07:23 +01:00
Volker Lendecke
0bee8719b2 talloc: Fix a typo 2012-01-02 14:59:59 +01:00
Michael Adam
6560bca57e talloc: fix a comment typo 2011-10-26 02:44:02 +02:00
Volker Lendecke
4ee613ba64 talloc: Remove an unused variable
Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Wed Sep  7 16:47:26 CEST 2011 on sn-devel-104
2011-09-07 16:47:26 +02:00
Andrew Tridgell
cf986f2008 talloc: ensure the sibling linked list remains valid during a free
This ensures that the sibling list of a pointer doesn't become invalid
during a free operation. It is an alternative fix to the fix in
6f51a1f45b, and avoids the problem of
trying to calculate the parent pointer early

This should fix the subtle spoolss talloc bug that Simo found

Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Tue Aug  9 01:53:17 CEST 2011 on sn-devel-104
2011-08-09 01:53:16 +02:00
Simo Sorce
52182a5281 talloc: preserve context name on talloc_free_children()
Otherwise tc->name will end up pointing to garbage when it is not
set to a const but rather to a string allocate as child of the context itself.

Signed-off-by: Andrew Tridgell <tridge@samba.org>
2011-07-29 18:17:44 +10:00
Stefan Metzmacher
df2cb2f672 talloc: splitout _talloc_free_children_internal()
metze

Autobuild-User: Stefan Metzmacher <metze@samba.org>
Autobuild-Date: Tue May 17 10:49:13 CEST 2011 on sn-devel-104
2011-05-17 10:49:13 +02:00
Stefan Metzmacher
38633c9f0b talloc: fixed a use after free error in talloc_free_children()
This is similar to commit 6f51a1f45b.

metze
2011-05-17 09:46:04 +02:00
Stefan Metzmacher
f3b855d2ff talloc: use _talloc_free_internal() in talloc_free_children()
metze
2011-05-17 09:46:04 +02:00
Stefan Metzmacher
c281f2fc1a talloc: setup the new 'tc' before TC_UNDEFINE_GROW_CHUNK() _talloc_realloc()
metze
2011-05-17 08:22:23 +02:00
Stefan Metzmacher
7102105c89 talloc: make really sure only optimize realloc if there's only one pool chunk
*talloc_pool_objectcount(pool_tc) == 2 doesn't mean the one of the objects
is the pool itself! So we better check for == 1 and calculate the chunk count.

metze
2011-05-17 08:22:21 +02:00
Stefan Metzmacher
14b662ee4f talloc: make use of _talloc_free_poolmem() in _talloc_realloc()
This should follow the same logic...

metze
2011-05-17 08:22:20 +02:00
Stefan Metzmacher
2d514be1ed talloc: split the handling of FLAG_POOL/FLAG_POOLMEM in _talloc_free_internal
The optimization of the object_count == 1 case should only happen
for when we're not destroying the pool itself. And it should only
happen if the pool itself is still valid.

If the pool isn't valid (it has TALLOC_FLAG_FREE),
object_count == 1 does not mean that the pool is the last object,
which can happen if you use talloc_steal/move() on memory
from the pool and then free the pool itself.

Thanks to Volker for noticing this!

metze
2011-05-17 08:22:18 +02:00
Stefan Metzmacher
f0f5ac18e5 talloc: use TC_UNDEFINE_SHRINK_CHUNK() instead of TC_INVALIDATE_SHRINK_CHUNK() for realloc path
If we optimize on top of raw realloc() we need
TC_INVALIDATE_SHRINK_CHUNK together with TC_UNDEFINE_GROW_CHUNK
(with was missing and caused false positive valgrind warnings).

But that is really slow, as we do a lot of talloc_realloc calls in samba.

That's why we only to TC_UNDEFINE_SHRINK_CHUNK() for now.

metze
2011-05-02 13:58:22 +02:00
Stefan Metzmacher
94a97bf64c talloc: fix compiler warnings with -Wc++-compat
metze

Autobuild-User: Stefan Metzmacher <metze@samba.org>
Autobuild-Date: Wed Apr 13 14:33:23 CEST 2011 on sn-devel-104
2011-04-13 14:33:23 +02:00
Stefan Metzmacher
2146ffd764 talloc: include valgrind headers if available
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
73cc85ac90 talloc: add TC_INVALIDATE_POOL marco
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
9c9f208598 talloc: add TC_UNDEFINE_GROW_CHUNK() marco
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
6126c3506d talloc: add TC_INVALIDATE_SHRINK_CHUNK() marco
This invalidates the unused bytes if we shrink memory.

metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
4895f55f06 talloc: add TC_INVALIDATE_FULL_CHUNK() macro
This makes it easier to mark a talloc pointer as
invalid.

metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
efbb35824e talloc: use VALGRIND_MAKE_MEM_UNDEFINED() before memmove()
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
1e70439f77 talloc: optimize talloc_free() and talloc_realloc() for talloc pools
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
73330f8436 talloc: add TC_POOL_FIRST_CHUNK() macro
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
13fab67995 talloc: add TC_POOL_SPACE_LEFT() macro
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
4084cb723c talloc: add TC_ALIGN16() macro
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:10 +02:00
Stefan Metzmacher
d39940113a talloc: use TC_HDR_SIZE instead of sizeof(struct talloc_chunk)
As this includes the padding to 16 bytes.

metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
2011-04-08 09:28:09 +02:00
Andrew Tridgell
6f51a1f45b talloc: fixed a use after free error
this is the minimal fix for the problem Rusty found. I previously
thought that the best fix would be to change tc->parent to be valid
for all pointers, but that is expensive for realloc with large numbers
of child pointers, which is much more commmon than I expected it to
be.

Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Wed Jan  5 07:22:27 CET 2011 on sn-devel-104
2011-01-05 07:22:27 +01:00
Jelmer Vernooij
733bc1c1ca talloc: Clarify error message on access after free. 2011-01-05 01:01:28 +01:00
Andrew Tridgell
999f3ed2ce talloc: added TALLOC_FREE_FILL environment variable
when this environment variable is set, talloc will fill freed memory
with the value from that environment variable. This can be used to
help find use after free bugs when valgrind is too slow to be used
2010-11-19 15:17:42 +11:00
Volker Lendecke
b5ed09c3af Move talloc_enable_null_tracking() to the s3 daemons 2010-10-08 21:11:45 +02:00
Andrew Tridgell
ba2c394ed4 talloc: fixed spelling errors in comment 2010-09-15 15:39:34 +10:00
Andrew Tridgell
45be1c7ba4 talloc: there is no ambiguity when freeing a ptr with a null parent
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-04-20 15:50:27 +10:00
Andrew Tridgell
ef496e8d1d talloc: mark public functions as _PUBLIC_ 2010-04-18 15:00:37 +10:00
Andrew Tridgell
fde50c633f talloc: a useful bit of debug code
this is useful when tracking down talloc loops. It is probably too
expensive to have on by default.
2010-04-02 18:52:29 +11:00
Andrew Tridgell
1b4bbec523 talloc: add a define for TALLOC_MAX_DEPTH
Thanks to the suggestion from simo
2010-04-02 18:52:29 +11:00
Andrew Tridgell
ff2b7d42e6 talloc: limit the depth that talloc will go for talloc_is_parent()
We have a bug in the dcerpc registry code that can cause a talloc loop
that chews unlimited CPU because of talloc_is_parent() during a
talloc_free()
2010-04-02 13:15:18 +11:00
Kamen Mazdrashki
8efabcc8a5 talloc: Fix write behind memory block
If ALWASY_REALLOC is defined and we are to 'shrink' memory block,
memcpy() will write outside memory just allocated.

Signed-off-by: Andrew Tridgell <tridge@samba.org>
2009-12-08 12:39:10 +11:00
Andrew Tridgell
3c5d763962 talloc: fixed talloc_disable_null_tracking()
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
2009-09-20 13:14:40 -07:00
Andrew Tridgell
78338d431c talloc: don't crash if f is NULL in talloc_report_*
It's annoying when you use 
  p talloc_report_full(ctx, fopen("/tmp/xx","w"))
in gdb, and if you don't have write permission on the file then
you get a segv.
2009-09-17 21:52:28 -07:00
Andrew Tridgell
00fb6705ff talloc: when we enable NULL tracking, reparent the autofree context
If NULL tracking is enabled after the autofree context is initialised
then autofree ends up separate from the null_context. This means that
talloc_report_full() doesn't report the autofree context. Fix this by
reparenting the autofree context when we create the null_context.
2009-09-15 18:45:41 -07:00
Andrew Tridgell
27b19eb9f6 report the location of the original talloc_free on double free
When we get a double free abort from talloc it is often hard to work
out where the first free came from. This patch takes advantage of the
fact that _talloc_free() now takes a location the free was called from
to allow the double free abort code to print the location of the first
free that conflicts.
2009-09-04 14:40:51 +10:00
Stefan Metzmacher
6c9ace27c5 talloc: add defines and functions for TALLOC_MAJOR/MINOR_VERSION
We also use the major and minor versions in the TALLOC_MAGIC,
so that we can detect if two conflicting versions of talloc
are loaded in one process. In this case we use talloc_log() to
output a very useful debug message before we call
talloc_abort().

metze
2009-08-24 16:29:58 +10:00
Stefan Metzmacher
5760edeeb6 talloc: remove ABI compat functions
metze
2009-08-24 16:29:58 +10:00
Stefan Metzmacher
8a90c8bc98 talloc: remove unused build dependecies to samba
metze
2009-08-24 16:29:58 +10:00
Stefan Metzmacher
e40f3144f2 talloc: add talloc_set_log_fn() and talloc_set_log_stderr()
So that the application can setup a log function to get ERROR
and WARNING messages.

metze
2009-08-24 16:29:58 +10:00
Stefan Metzmacher
ac8aeec824 talloc: let talloc_steal() only generate a warning if it's used with references
We have to many callers, which rely on that talloc_steal() never fails.

metze
2009-08-24 16:29:57 +10:00
Stefan Metzmacher
1fbc86c57a talloc: call return after abort, because an overloaded abort function might not exit
This will be useful in the testsuite,
where we could check if an abort would happen.

metze
2009-08-24 16:29:57 +10:00