Files
codeql/cpp/ql/src/Critical/UseAfterFree.cpp
Jeroen Ketema 0c0720a962 C++: Improve use-after-free example code
* Remove the mismatch between `new` and `free` and use `delete` instead
* Make the function `void`, so people copying the code will not forget
  to add a `return`.
* Balance out the `...` for omitted code.
2023-08-03 11:06:15 +02:00

11 lines
186 B
C++

void f() {
char* buf = new char[SIZE];
...
if (error) {
delete buf; //error handling has freed the buffer
}
...
log_contents(buf); //but it is still used here for logging
...
}