]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
coccinelle: add test on realloc
authorEric Leblond <eric@regit.org>
Thu, 12 Dec 2013 12:34:54 +0000 (13:34 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 13 Dec 2013 12:51:41 +0000 (13:51 +0100)
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.

qa/coccinelle/realloc.cocci [new file with mode: 0644]

diff --git a/qa/coccinelle/realloc.cocci b/qa/coccinelle/realloc.cocci
new file mode 100644 (file)
index 0000000..0b82880
--- /dev/null
@@ -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)