Skip to content

Commit debc441

Browse files
authored
Merge pull request #1158 from geoffw0/moremsalloc
CPP: Add more allocation functions to Alloc.qll
2 parents 4d4055a + bdd6965 commit debc441

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

change-notes/1.21/analysis-cpp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
| **Query** | **Expected impact** | **Change** |
1313
|----------------------------|------------------------|------------------------------------------------------------------|
1414
| Mismatching new/free or malloc/delete (`cpp/new-free-mismatch`) | Fewer false positive results | Fixed an issue where functions were being identified as allocation functions inappropriately. Also affects `cpp/new-array-delete-mismatch` and `cpp/new-delete-array-mismatch`. |
15+
| Memory may not be freed (`cpp/memory-may-not-be-freed`) | More correct results | Support added for more Microsoft-specific allocation functions, including `LocalAlloc`, `GlobalAlloc`, `HeapAlloc` and `CoTaskMemAlloc`. |
16+
| Memory is never freed (`cpp/memory-never-freed`) | More correct results | Support added for more Microsoft-specific allocation functions, including `LocalAlloc`, `GlobalAlloc`, `HeapAlloc` and `CoTaskMemAlloc`. |
1517
| Resource not released in destructor (`cpp/resource-not-released-in-destructor`) | Fewer false positive results | Resource allocation and deallocation functions are now determined more accurately. |
1618

1719
## Changes to QL libraries

cpp/ql/src/semmle/code/cpp/commons/Alloc.qll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ predicate allocationFunction(Function f)
3939
name = "MmAllocateNodePagesForMdlEx" or
4040
name = "MmMapLockedPagesWithReservedMapping" or
4141
name = "MmMapLockedPages" or
42-
name = "MmMapLockedPagesSpecifyCache"
42+
name = "MmMapLockedPagesSpecifyCache" or
43+
name = "LocalAlloc" or
44+
name = "LocalReAlloc" or
45+
name = "GlobalAlloc" or
46+
name = "GlobalReAlloc" or
47+
name = "HeapAlloc" or
48+
name = "HeapReAlloc" or
49+
name = "VirtualAlloc" or
50+
name = "CoTaskMemAlloc" or
51+
name = "CoTaskMemRealloc"
4352
)
4453
)
4554
}
@@ -81,7 +90,17 @@ predicate freeFunction(Function f, int argNum)
8190
(name = "MmFreeMappingAddress" and argNum = 0) or
8291
(name = "MmFreePagesFromMdl" and argNum = 0) or
8392
(name = "MmUnmapReservedMapping" and argNum = 0) or
84-
(name = "MmUnmapLockedPages" and argNum = 0)
93+
(name = "MmUnmapLockedPages" and argNum = 0) or
94+
(name = "LocalFree" and argNum = 0) or
95+
(name = "GlobalFree" and argNum = 0) or
96+
(name = "HeapFree" and argNum = 2) or
97+
(name = "VirtualFree" and argNum = 0) or
98+
(name = "CoTaskMemFree" and argNum = 0) or
99+
(name = "SysFreeString" and argNum = 0) or
100+
(name = "LocalReAlloc" and argNum = 0) or
101+
(name = "GlobalReAlloc" and argNum = 0) or
102+
(name = "HeapReAlloc" and argNum = 2) or
103+
(name = "CoTaskMemRealloc" and argNum = 0)
85104
)
86105
)
87106
}

0 commit comments

Comments
 (0)