Skip to content

Commit

Permalink
Fix undefined behaviour delete
Browse files Browse the repository at this point in the history
Using `operator delete` on an `operator new[]` allocated memory is an undefined behaviour.

"The behavior of the standard library implementation of this function is undefined unless ptr is a null pointer or is a pointer previously obtained from the standard library implementation of operator new(std::size_t) or operator new(std::size_t, std::nothrow_t)."

https://stackoverflow.com/a/2425749/5795772
https://en.cppreference.com/w/cpp/memory/new/operator_delete
  • Loading branch information
TheNNX authored and dz333n committed Apr 8, 2024
1 parent b7af089 commit a3831c1
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions SubsystemTool/SubsystemTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ int ProcessPath(_TCHAR* path, _TCHAR* subsys, BOOL ResetVersion)
return 5;
}

delete fileBuf;

delete[] fileBuf;
CloseHandle(hFile);
}

Expand Down

0 comments on commit a3831c1

Please sign in to comment.