This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

alloca is bad?


A patch that I recently submitted to gdb-patches used the alloca ()
function to allocate memory.  I've been told in private email that I
mustn't use alloca because "stack corruption problems are harder to
debug" than heap corruption problems.

I was surprised by this assertion and so I thought I'd ask for a
consensus here.  Should the use of alloca be deprecated in gdb?

It is my assertion that the amount of bookkeeping and overhead required
to use malloc in a way that is analogous with alloca essentially
nullifies the "harder to debug" argument.  malloc requires a free and
many times, in gdb context, the only way to guarantee a free is with the
use of the cleanup function.  Any time you add the complexity of
something like 'cleanup()' (or whatever other mechanism you use to
ensure that what you malloc is automatically freed) you can't claim to
have reduced debugging problems.  Speaking of free, with alloca you
don't have memory leaks.  With malloc, you do.

If alloca is bad, then why are local arrays and pointers to local
variables and parameters ok?

Inquiring minds...

cgf

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]