Problem with finding mistake in program with using valgrind
By : Tani
Date : August 01 2020, 03:00 AM
hope this fix your issue You forget that in C all char strings are really called null-terminated byte strings. The null-terminated bit it important, and will be used to find the end of the strings (by e.g. strlen). If it's missing strings functions will go out of bounds and you will have undefined behavior.
char *novy = malloc(strlen(text) + 1); // +1 to make room for the terminator
It is taking forever for valgrind to find memory leaks but its takes seconds for the program to run without valgrind
By : rw93
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , There is no problem as far as I can see unless you can verify an infinite loop or some other run-time error ... Valgrind basically acts like a virtual machine or virtual execution environment running the program, watching all variables, memory allocations, etc., etc. and therefore will run quite a bit slower than native code. You'll get the same effect if you ran your program inside a debugger like gdb and set it to watch every writable memory location.
Unit tests take a long time to run. Valgrind problem? Gcov problem?
help you fix your problem You're allocating chocolateMakers twice (line 93 first and line 36 then) and chocolateEaters twice too (line 94 first and line 62 then). In both cases, you're overwriting the pointer resulting of the first allocation with the one resulting of the second allocation. When you free the allocated memory, you're doing it only once, with the pointers of the second allocations. The pointers of the first allocation are lost, the memory allocated is never freed.