Fix autofree context not to be done in fork() child.
Fix comment above talloc_array_size.
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
/* use this to force every realloc to change the pointer, to stress test
code that might not cope */
/* use this to force every realloc to change the pointer, to stress test
code that might not cope */
NULL
*/
static void *null_context;
NULL
*/
static void *null_context;
-static void *autofree_context;
+static pid_t *autofree_context;
static void *(*tc_external_alloc)(void *parent, size_t size);
static void (*tc_external_free)(void *ptr, void *parent);
static void *(*tc_external_alloc)(void *parent, size_t size);
static void (*tc_external_free)(void *ptr, void *parent);
+ if (unlikely(tc->flags & TALLOC_FLAG_EXT_ALLOC))
+ oldparent = talloc_parent(ptr);
+
- oldparent = TC_PTR_FROM_CHUNK(tc->parent);
_TLIST_REMOVE(tc->parent->child, tc);
if (tc->parent->child) {
tc->parent->child->parent = tc->parent;
_TLIST_REMOVE(tc->parent->child, tc);
if (tc->parent->child) {
tc->parent->child->parent = tc->parent;
static void talloc_autofree(void)
{
static void talloc_autofree(void)
{
- _talloc_free(autofree_context);
+ if (autofree_context && *autofree_context == getpid())
+ _talloc_free(autofree_context);
*/
void *talloc_autofree_context(void)
{
*/
void *talloc_autofree_context(void)
{
- if (autofree_context == NULL) {
- autofree_context = _talloc_named_const(NULL, 0, "autofree_context");
+ if (autofree_context == NULL || *autofree_context != getpid()) {
+ autofree_context = talloc(NULL, pid_t);
+ *autofree_context = getpid();
+ talloc_set_name_const(autofree_context, "autofree_context");
+
talloc_set_destructor(autofree_context, talloc_autofree_destructor);
atexit(talloc_autofree);
}
talloc_set_destructor(autofree_context, talloc_autofree_destructor);
atexit(talloc_autofree);
}
#define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
/**
#define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
/**
- * talloc_zero_array - allocate an array of zeroed types
+ * talloc_array_size - allocate an array of elements of the given size
* @ctx: context to be parent of this allocation, or NULL.
* @ctx: context to be parent of this allocation, or NULL.
- * @type: the type to be allocated.
+ * @size: the size of each element
* @count: the number of elements to be allocated.
*
* @count: the number of elements to be allocated.
*
- * Just like talloc_array, but zeroes the memory.
+ * Typeless form of talloc_array.
*/
#define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__)
*/
#define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__)