you need to distinguish between stack errors and memory heaps.
Walgrind tells you that part of the memory has not been freed, and some may have been lost. but this may have nothing to do with your real problem: stack destruction.
stack means: local variables (often with character arrays), any other arrays that are not placed, etc.
heap: everything that was allocated using malloc, calloc, realloc, etc.
So if you break the stack, chances are good that you write somewhere on top of the end of the array. First check strcpy, memcpy, and array access (where you write to memory that was not allocated).
Chris source share