This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Libbacktrace backtrace_vector_finish
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 5 Dec 2013 16:32:30 +0100
- Subject: Libbacktrace backtrace_vector_finish
- Authentication-results: sourceware.org; auth=none
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
I'm trying to understand how the backtrace_vector_* APIs are meant to work
and used, but at least for alloc.c don't see how it can work properly:
Both backtrace_vector_grow and backtrace_vector_release use
base = realloc (vec->base, alc);
or
vec->base = realloc (vec->base, vec->size);
(note, in the latter case it is even a memory leak if realloc fails),
but that assumes that that vec->base has been returned by malloc/realloc
etc. But,
void
backtrace_vector_finish (struct backtrace_state *state ATTRIBUTE_UNUSED,
struct backtrace_vector *vec)
{
vec->base = (char *) vec->base + vec->size;
vec->size = 0;
}
will change vec->base so that it no longer is an address returned by
malloc/realloc, so next time you call backtrace_vector_grow, if it will
actually need to reallocate anything, it will crash in realloc or silently
misbehave. If this works properly in mmap.c implementation, perhaps
backtrace_vector_finish in alloc.c should just backtrace_vector_release
and memset (*vec, 0, sizeof (*vec)); ?
Jakub