alloc/release guards ?

Hartmut Schirmer hartmut.schirmer@arcormail.de
Fri Apr 14 11:46:00 GMT 2000


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




More information about the Gcc mailing list