mirror of https://github.com/OISF/suricata
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
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…
Reference in New Issue