This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
alloc/release guards ?
- To: gcc at gcc dot gnu dot org
- Subject: alloc/release guards ?
- From: Hartmut Schirmer <hartmut dot schirmer at arcormail dot de>
- Date: Fri, 14 Apr 2000 20:35:11 +0200
- Reply-To: hartmut dot schirmer at arcormail dot de
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