C++: Move qhelp.

This commit is contained in:
Geoffrey White
2024-05-07 16:35:11 +01:00
parent 541effb8cb
commit dd95a2abab
2 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
int* f() {
int *buff = malloc(SIZE*sizeof(int));
do_stuff(buff);
free(buff);
int *new_buffer = malloc(SIZE*sizeof(int));
free(buff); // BAD: If new_buffer is assigned the same address as buff,
// the memory allocator will free the new buffer memory region,
// leading to use-after-free problems and memory corruption.
return new_buffer;
}