A moment, I wasn't talking about memory leaks, but just about memory manipulation (this happens often to me because I'm a non-native english guy, I could counfound some terms), as I saw you were talking about that, see what happens when someone doesn't think?...
Originally Posted by
Yamiez
Did you even read the code?
If ReadProcessMemory fails or if the pattern is not found the memory is leaked.
Of course, you must always ensure that:
delete [] data
is always called.
- - - Updated - - -
Basically it has memory leaks, because you have:
Code:
if (!ReadProcessMemory(_process, (LPVOID)start, data, size, &bytesRead)) {
return NULL;
}
which fires then you have leaked data as he never calls delete [] before returning. He also leaks at the end of the function as he never calls delete [] before returning. @Yamiez I'm sure you noticed there is an incorrect delete in this part:
Code:
for (DWORD i = 0; i < size; i++) {
if (DataCompare((const BYTE*)(data + i), (const BYTE*)sig, mask)) {
delete data;
return start + i;
}
}
It's an ub (undefined behavior) to call delete on an allocated pointer with new[] (if you use new[], you need to use delete[]).
Also probably you noticed that a smart pointer would be nice:)