VLD causes issues - memory-leaks

ALL,
I have MSVC 2017 Community and trying to find where is the memory leak in my program.
I did compile and link against the VLD and I did copy vld_x86.dll, dbghelp.dll and Microsoft.DTfW.DHL.manifest to the same place where executable is.
Trying to run the program under MSVC I am getting
wntdll.pdb not loaded
exception.
If I build without VLD, program starts without any issues.
What is a way to debug memory leaks with MSVC?
TIA!!

Related

Leak/Address sanitizer in a shared library without LD_PRELOAD

I'm looking to use Clang's leak/address sanitizer on my shared library, which is loaded from JVM or dotnet (Linux) at runtime, so I can't recompile the binary.
Using LD_PRELOAD makes for a very noisy output, a lot (presumably false positive?) leaks get reported from the JVM itself. The sanitizer outright crashes when LD_PRELOADing for dotnet.
Is there any way to statically link the sanitizer into the shared library (or dynamically without LD_PRELOAD)?
First thing first, you can not statically link sanitizer runtime libs into your library. It has to be preloaded to intercept std allocator (malloc, etc.) and would malfunction otherwise (there's a special check at Asan startup that ensures that libasan was preloaded).
Noisy output in JVM may well be legitimate errors.
Using LD_PRELOAD makes for a very noisy output, a lot (presumably false positive?) leaks get reported from the JVM itself.
The sanitizer outright crashes when LD_PRELOADing
for dotnet.
Is it a real crash or diagnosed memory error? Crash can be reported in Asan tracker.
Memory error should be reported to dotnet project but you can still continue execution after it using continue-after-error mode (grep for "continue-after-error" in Asan FAQ).

MSVC 2010 - Error 0xc000007b when building in x64

The title is pretty straightforward - I can't get anything at all to run when building in x64 and I get a message box with this error code. Do you know what may be the problem here?
This is STATUS_INVALID_IMAGE_FORMAT, you can find these error codes listed in the ntstatus.h SDK header file.
It is certainly strongly correlated with building x64 code. You'll get this status code whenever your program has a dependency on 32-bit code, particularly in a DLL. Your program will fail to start when it tries to load the DLL at startup, a 64-bit process cannot contain any 32-bit code. Or the other way around, a 32-bit process trying to load a 64-bit DLL.
Review all the dependencies for your program, particularly the import libraries you link. Everything must be built to target x64. You can use SysInternals' ProcMon utility to find the DLL that fails to load, useful in case this is a DLL Hell problem.
Just an addition to the correct answer above: also check you .manifest-files (resp. #pragma comment(linker,"/manifestdependency...) and make sure that you have processorArchitecture='x86' for 32-bit and processorArchitecture='amd64' for x64 code.

Run-time errors and memory leaks detection

Created application is working toooo slow, looks like there are a lot of memory leaks, there are a lot of pointers. So, please, can you advice some effective tool for run-time errors and memory leaks detection in Visual Studio C++?
You can use deleaker. It must help you.
I know 2 good tools for windows: Purify and Insure++.
For linux: Valgrind.
If you use the debug version of the CRT library , you can use find all memory leaks very easily.
Basically after including appropriate headers you call
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
somewhere in the beginning of you program.
Before the program exits you should call
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
Which dumps all the memory leaks to Debug Output Window.
But the application being slow might be unrelated to memory leaks, For performance profiling you can follow directions as per Find Application Bottlenecks with Visual Studio Profiler
For catching bad C++ constructs at compile time, you can use the static code analysis feature of Visual Studio 2010 or later.

Program runs with gdb but doesn't run with ./ProgramName

I am writing an editor in assembly 64bit mode in linux. It runs correctly when I debug the program in GDB but it does not run correctly when I run it normally it means it has runtime errors when I use ./programName .
You're probably accessing uninitialized data or have some kind of memory corruption problem. This would explain the program behaving differently when run in the debugger - you're seeing the results of undefined behavior.
Run your program through valgrind's memcheck tool and see what it outputs. Valgrind is a powerful tool that will identify many runtime errors on Linux, including a full stack trace to the error.
If GDB disabling ASLR is what makes it work, perhaps set disable-randomization off in GDB will let your reproduce a crash inside GDB so you can debug it. Force gdb to load shared library at randomized address.
Otherwise enable core dumps from your program, and use GDB on the core dump.
gdb ./prog core.1234.
On x86, you can insert a ud2 instruction in your asm source to intentionally cause a crash at whatever point you want in your code, if you want to get a coredump to examine registers/memory at some point before it crashes on its own. All architectures have an undefined instruction you can use, but I only know the mnemonic for x86's off the top of my head.

dll size (debug and release)

I have read in other discussions that Release dlls have reduced size compared to Debug dlls. But why is it that the size of the dll I have made is the other way around: the Release dll is bigger than the Debug dll. Will it cause problems?
It won't cause problems, its probably that the compiler is 'inlining' more items in the release build and creating larger code. It all depends on the code itself.
Nothing to worry about.
EDIT:
If you are really worried about and not worried about speed you can turn on optimize for size. Or turn off auto inlining and see what difference you get.
EDIT:
More info, you can use dumpbin /headers to see where the dll gets larger
How much bigger is your Release DLL than your Debug DLL?
Your Debug DLLs might seem small is you are generating PDB symbol files (so the debug symbol is not actually in the DLL file). Or if you are inadvertently compiling debug symbols into your Release DLL.
This can be caused by performance optimizations like loop unrolling - if it's significantly different, check your Release linker settings to make sure that you're not statically compiling anything in.
The performance can be influenced if your application perform tasks of high performance. A release version can even be larger than a debug version, if marked options to generate code with information on Debug included. But this also depends on the compiler you are using.

Resources