I am having the following error when I run Valgrind, I tried to free all the used functions, but still have the same error message
==303912== HEAP SUMMARY:
==303912== in use at exit: 348 bytes in 2 blocks
==303912== total heap usage: 1,192 allocs, 1,190 frees, 153,918 bytes allocated
==303912==
==303912== 348 bytes in 2 blocks are still reachable in loss record 1 of 1
==303912== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==303912== by 0x490050E: strdup (strdup.c:42)
==303912== by 0x109B8E: main (minishell.c:178)
==303912==
==303912== LEAK SUMMARY:
==303912== definitely lost: 0 bytes in 0 blocks
==303912== indirectly lost: 0 bytes in 0 blocks
==303912== possibly lost: 0 bytes in 0 blocks
**==303912== still reachable: 348 bytes in 2 blocks**
==303912== suppressed: 0 bytes in 0 blocks
==303912==
==303912== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Line 42 in valgrind error message refers to "signal_value = 1", not sure why?!:
sigjmp_buf jmpbuf;
volatile sig_atomic_t signal_value= false;
void catch_signal(int sign) {
if (!signal_value) {
write(STDOUT_FILENO, "\n", 1);
siglongjmp(jmpbuf, 1);
signal_value = 1;
}
else{
signal_value = 0;
printf("\n");
}
}
and line 178 here is right at "argvals[num_tokens] = strdup(token);" the second part where it is referring to in valgrind
while(token!=NULL) {
argvals[num_tokens] = strdup(token);
num_tokens++;
token = strtok(NULL, " ");
}
if (num_tokens == 0) {
continue;
} if (strcmp(argvals[0], "exit") == 0) {
for (int j = 0; j < num_tokens; j++) {
free((char*)argvals[j]);
}
return EXIT_SUCCESS;
}