Answer the question
In order to leave comments, you need to log in
How to solve a memory leak issue?
The crux of the matter is what are the options to avoid memory leaks.
As an example, here is an implementation of xor with a memory leak:
wchar_t* xorCipher(const wchar_t* toEncrypt) {
HANDLE hHeap = GetProcessHeap();
if (hHeap != NULL) {
const int size = _wcslen(toEncrypt);
wchar_t* result = (wchar_t*)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(wchar_t) * size);
if (result != NULL) {
for (int i = 0; i != _wcslen(toEncrypt) + 1; i++) {
result[i] = toEncrypt[i] ^ (wchar_t)key;
}
}
return result;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question