I’m trying to make logical sense of valgrind errors from this section of code. For these command paths, there are no errors.
I need help with finding what to look for in the code to find the problem. The full code is too big to post.
This is the middle section.
if (argc >= 2)
{
if ((strcmp (argv[1],"--linux") == 0) || (strcmp (argv[1],"-l") == 0))
{
//if (argc == 3)
//{
//}
printf("
.....Scanning linux - Clamscan Engine.....
");
/* Open the command for reading. */
FilePtr = popen("ls -l", "r");
if (FilePtr == NULL)
printf("error: clamscan failed
" );
else
{
/* Read the output a line at a time - output it. */
while ((nread = getline(&line, &len, FilePtr)) != -1)
printf("'%s'", line);
free(line);
/* close */
pclose(FilePtr);
}
}
else if ((strcmp (argv[1],"--help") == 0) || (strcmp (argv[1],"-h") == 0))
print_menu();
else if ((strcmp (argv[1],"--version") == 0) || (strcmp (argv[1],"-v") == 0))
{
puts(
"Title: scanvirus
"
"Description: virus scanning application, clamscan anti-virus engine
"
"Author: Lord Valarian
"
"Version: 1.0.0 bin - beta
"
"Build #2020.07.21.21.21
"
"Engine: ClamAV v0.100.3
"
"Virus Vault: /var/log/VirusVault
"
"Virus Reports: /var/log/VirusVault/VirusFound
"
"Configuration: /var/log/VirusVault/scanvirus.cfg
"
"Virus Scan Logs: /var/log/VirusVault/VirusScanLog.txt
"
"
");
FilePtr2 = fopen(VirusConfig, "r");
if (FilePtr2 == NULL)
perror("fopen: VirusConfig");
//exit(EXIT_FAILURE);
else
{
while ((nread = getline(&line, &len, FilePtr2)) != -1)
printf("'%s' len(%d)", line, len);
free(line);
fclose(FilePtr2);
}
}
}
This means the first section of code and the end should have no memory issues.
valgrind --leak-check=full scanvirusbin
==8426==
==8426== HEAP SUMMARY:
==8426== in use at exit: 0 bytes in 0 blocks
==8426== total heap usage: 16 allocs, 16 frees, 10,688 bytes allocated
==8426==
==8426== All heap blocks were freed – no leaks are possible
==8426==
==8426== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
valgrind --leak-check=full scanvirusbin -h
==8432==
==8432== HEAP SUMMARY:
==8432== in use at exit: 0 bytes in 0 blocks
==8432== total heap usage: 16 allocs, 16 frees, 10,688 bytes allocated
==8432==
==8432== All heap blocks were freed – no leaks are possible
==8432==
==8432== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
I can’t find any mistakes in that code. What does this group of errors mean ??