I'm programming a simple application and currently Im trying to get rid of all memory leaks. There are some that I cannot figure out. For example consider the code below:
Then all I do is create a wstring variable called "pcName" and execute this code:
pcName = getComputerName();
Im using Visual Leak Detector and it tells me that the leak is in getComputerName() (the returning wstring) What should I do to avoid this memory leak?
The wstring does not leak. But you must not return nullptr for a [w]string. Even though I don't think that line 15 will ever be executed.
This code snippet is certainly not the source of the leak. Most likely it is falsely reported due to some undefined behavior somewhere else in your code.