This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

alloc/release guards ?


Hi,

an old problem hit me again today:

void f(void)
{
    if ( !alloc_resource() )
        return;
    // code using resource
    if ( error1 ) {
        release_resource();
        return;
    }
    // more code using resource
    if ( error2 )
        return;
    // again more code
    release_resource();
}

This pseudo-funktion shows the problem, the
error2 exit doesnīt release the resource (a
lock in the real program, might also be a malloc or
a disable IRQ or ...).

Flow analysis should be able to tell if there are
ways through alloc_resource() not reaching a 
release-resource(), but I didnīt find a hint in the
manual how to implement this in (GNU-)C

Question: Is there any way GCC could warn about this?
or:       Is it possible/easy to add such a warning ?

Thanks,
Hartmut



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