coccinelle: add test on realloc

If we use SCRealloc like:
 x = SCRealloc(x, ...)
then in case of failure we are loosing the original pointer value
and the memory is lost and can not be free.

This test just check for this construction and output an error if
it finds it.
pull/724/merge
Eric Leblond 11 years ago committed by Victor Julien
parent 1f07d1521e
commit 1fbaebad63

@ -0,0 +1,18 @@
@realloc@
expression x, E;
type ty;
position p1;
@@
(
x@p1 = SCRealloc(x, E)
|
x@p1 = (ty *) SCRealloc(x, E)
)
@script:python@
p1 << realloc.p1;
@@
print "Structure reallocated at %s:%s but original pointer is lost and not freed in case of error." % (p1[0].file, p1[0].line)
import sys
sys.exit(1)
Loading…
Cancel
Save