@@ -78,12 +78,6 @@ class MallocAllocationFunction extends AllocationFunction {
7878 // CoTaskMemAlloc(size)
7979 name = "CoTaskMemAlloc" and sizeArg = 0
8080 or
81- // alloca(size)
82- name = "alloca" and sizeArg = 0
83- or
84- // __builtin_alloca(size)
85- name = "__builtin_alloca" and sizeArg = 0
86- or
8781 // kmem_alloc(size, flags)
8882 name = "kmem_alloc" and sizeArg = 0
8983 or
@@ -96,6 +90,31 @@ class MallocAllocationFunction extends AllocationFunction {
9690 override int getSizeArg ( ) { result = sizeArg }
9791}
9892
93+ /**
94+ * An allocation function (such as `alloca`) that does not require a
95+ * corresponding free (and has an argument for the size in bytes).
96+ */
97+ class AllocaAllocationFunction extends AllocationFunction {
98+ int sizeArg ;
99+
100+ AllocaAllocationFunction ( ) {
101+ exists ( string name |
102+ hasGlobalName ( name ) and
103+ (
104+ // alloca(size)
105+ name = "alloca" and sizeArg = 0
106+ or
107+ // __builtin_alloca(size)
108+ name = "__builtin_alloca" and sizeArg = 0
109+ )
110+ )
111+ }
112+
113+ override int getSizeArg ( ) { result = sizeArg }
114+
115+ predicate requiresDealloc ( ) { none ( ) }
116+ }
117+
99118/**
100119 * An allocation function (such as `calloc`) that has an argument for the size
101120 * and another argument for the size of those units (in bytes).
@@ -243,6 +262,8 @@ class CallAllocationExpr extends AllocationExpr, FunctionCall {
243262 override int getSizeBytes ( ) { result = getSizeExpr ( ) .getValue ( ) .toInt ( ) * getSizeMult ( ) }
244263
245264 override Expr getReallocPtr ( ) { result = getArgument ( target .getReallocPtrArg ( ) ) }
265+
266+ override predicate requiresDealloc ( ) { target .requiresDealloc ( ) }
246267}
247268
248269/**
0 commit comments