}
if (tc->flags & TALLOC_FLAG_FREE) {
+ talloc_log("talloc: double free error - first free may be at %s\n", tc->name);
talloc_abort_double_free();
return NULL;
} else {
/*
internal talloc_free call
*/
-static inline int _talloc_free_internal(void *ptr)
+static inline int _talloc_free_internal(void *ptr, const char *location)
{
struct talloc_chunk *tc;
* pointer.
*/
is_child = talloc_is_parent(tc->refs, ptr);
- _talloc_free_internal(tc->refs);
+ _talloc_free_internal(tc->refs, location);
if (is_child) {
- return _talloc_free_internal(ptr);
+ return _talloc_free_internal(ptr, location);
}
return -1;
}
struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs);
if (p) new_parent = TC_PTR_FROM_CHUNK(p);
}
- if (unlikely(_talloc_free_internal(child) == -1)) {
+ if (unlikely(_talloc_free_internal(child, location) == -1)) {
if (new_parent == null_context) {
struct talloc_chunk *p = talloc_parent_chunk(ptr);
if (p) new_parent = TC_PTR_FROM_CHUNK(p);
tc->flags |= TALLOC_FLAG_FREE;
+ /* we mark the freed memory with where we called the free
+ * from. This means on a double free error we can report where
+ * the first free came from
+ */
+ tc->name = location;
+
if (tc->flags & (TALLOC_FLAG_POOL|TALLOC_FLAG_POOLMEM)) {
struct talloc_chunk *pool;
unsigned int *pool_object_count;
if (_talloc_steal_internal(new_parent, h) != h) {
return NULL;
}
- return (void *)ptr;
+ return discard_const_p(void, ptr);
}
}
return -1;
}
- return _talloc_free_internal(h);
+ return _talloc_free_internal(h, __location__);
}
/*
tc_p = talloc_chunk_from_ptr(ptr);
if (tc_p->refs == NULL) {
- return _talloc_free_internal(ptr);
+ return _talloc_free_internal(ptr, __location__);
}
new_p = talloc_parent_chunk(tc_p->refs);
va_end(ap);
if (unlikely(name == NULL)) {
- _talloc_free_internal(ptr);
+ _talloc_free_internal(ptr, __location__);
return NULL;
}
va_end(ap);
if (unlikely(name == NULL)) {
- _talloc_free_internal(ptr);
+ _talloc_free_internal(ptr, __location__);
return NULL;
}
return -1;
}
- return _talloc_free_internal(ptr);
+ return _talloc_free_internal(ptr, location);
}
void *_talloc_move(const void *new_ctx, const void *_pptr)
{
const void **pptr = discard_const_p(const void *,_pptr);
- void *ret = talloc_steal(new_ctx, (void *)*pptr);
+ void *ret = talloc_steal(new_ctx, discard_const_p(void, *pptr));
(*pptr) = NULL;
return ret;
}