8000 Merge pull request #5569 from geoffw0/memoryfree · jsutil/codeql@fe76b08 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe76b08

Browse files
authored
Merge pull request github#5569 from geoffw0/memoryfree
C++: Add a test of memory freed queries with strdup.
2 parents 9283912 + 244966e commit fe76b08

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cpp/ql/test/query-tests/Critical/MemoryFreed/MemoryNeverFreed.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
| test.cpp:89:18:89:23 | call to malloc | This memory is never freed |
1111
| test.cpp:156:3:156:26 | new | This memory is never freed |
1212
| test.cpp:157:3:157:26 | new[] | This memory is never freed |
13+
| test.c A335 pp:167:14:167:19 | call to strdup | This memory is never freed |

cpp/ql/test/query-tests/Critical/MemoryFreed/test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,15 @@ int overloadedNew() {
156156
new(std::nothrow) int(3); // BAD
157157
new(std::nothrow) int[2]; // BAD
158158
}
159+
160+
// --- strdup ---
161+
162+
char *strdup(const char *s1);
163+
void output_msg(const char *msg);
164+
165+
void test_strdup() {
166+
char msg[] = "OctoCat";
167+
char *cpy = strdup(msg); // BAD
168+
169+
output_msg(cpy);
170+
}

0 commit comments

Comments
 (0)
0