Well, first an honest warning, this is a project for the class. I am not looking for any help other than fixing a memory leak. I guess I followed some terrifying coding methods in the space of this C code. Despite this, when I run Valgrind to look for a memory leak, it is completely unclear to me what memory leaks are missing. I know that there are at least two lines that I do not free, but I malloc () ed based solely on the output size of valgrind. Since I took some of the extraneous code from the project, valgrind line numbers may well be turned off, because of this I marked them with comments for your convenience.
A small background, I write the basic functions of the shell. He currently performs the following actions:
1. Enter user input
2. Enter the cmdin structure
3. Run the command if it does not have a channel.
4. free up the space created by cmdin, and start again in step 1. Here the problem arises.
#include <stdio.h>
Note: the input for this valgrind is as follows:
tosh$ ls -al tosh$ exit
Heap and leak briefs:
HEAP SUMMARY: ==4901== in use at exit: 4,096 bytes in 2 blocks ==4901== total heap usage: 6 allocs, 4 frees, 24,600 bytes allocated ==4901== ==4901== 2,048 bytes in 1 blocks are definitely lost in loss record 1 of 2 ==4901== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==4901== by 0x400A48: parse (tosh.c:46) ==4901== by 0x400C97: main (tosh.c:86) ==4901== ==4901== 2,048 bytes in 1 blocks are definitely lost in loss record 2 of 2 ==4901== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==4901== by 0x400BDE: parse (tosh.c:62) ==4901== by 0x400C97: main (tosh.c:86) ==4901== ==4901== LEAK SUMMARY: ==4901== definitely lost: 4,096 bytes in 2 blocks ==4901== indirectly lost: 0 bytes in 0 blocks ==4901== possibly lost: 0 bytes in 0 blocks ==4901== still reachable: 0 bytes in 0 blocks ==4901== suppressed: 0 bytes in 0 blocks
UPDATE: as requested. My Makefile:
CC=gcc CFLAGS=-g -Wall TARGET=tosh $(TARGET): $(TARGET).c $(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c
Valgrind Version: Valgrind-3.7.0
gcc Version: gcc (Ubuntu / Linaro 4.7.2-2ubuntu1) 4.7.2
echo $ LD_PRELOAD:
(It didn't print anything)