#Building a toy shell in C
41 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
Here's the entire source.
for memory leaks you can always valgrind it
I've inspected valgrind output using -fsanitize=address -undefined, I truly don't understand how to interpret it beyond looking at the given file and trying to mess things up further.
what did valgrind say?
so you see how each leak has like a number of places where it's called?
#0 is like the internal stuff
#1 is where the leak originates from
So I care less about #0 asan stuff and more about #1 the callee and #2 the caller?
yes
Ok, I have three separate direct leaks.
So for the first one, all signs point to this call :path = calloc(1, strlen(ptr) + 1 + strlen(s[0]) + 2);
That's in findpath.c
This is called from forkcmd.c ``` path = findpath(s);
child = fork();
if (child == 0)
{
if (execve(path, s, NULL) == -1)
{
write(1, s[0], strlen(s[0]));
write(1, ": ", 2);
writes(CMDNF);
free(path);
return (-1);
}
}
wait(&child);
free(path);```
Maybe I'm allocating too much memory?
!cref calloc
I didn't look into the semantic of your code yet but are you using calloc correctly?
it allocates num amount of size
Oh, maybe I'm not. Will switch those around and actually use sizeof(char) so I don't mess that up.
Direct leak of 869 byte(s) in 32 object(s) allocated from:
#0 0xffff2331e650 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:77
#1 0xaaaacf071d60 in findpath /home/muhammeda/src/alx/simple_path/findpath.c:15
#2 0xaaaacf072040 in forkcmd /home/muhammeda/src/alx/simple_path/forkcmd.c:19```
That's when I use path = calloc(strlen(ptr) + 1 + strlen(s[0]) + 2, 1);
To repeat this issue, exit on a line by itself won't do: You'd have to do more than one call of ls
!cref realloc
@knotty swan Do you think you have the time to go through the code with me?
Understand if you don't.
I'm on my computer now so I'll just test locally
Ok, thank you!
@unkempt cipher Has your question been resolved? If so, run !solved :)
No.
Just noticed another bug when I ls ... Sigh.
👀
@knotty swan Still here?
yeah sorry I went to manage things and homework 
maybe someone else can help on this thread
@unkempt cipher Has your question been resolved? If so, run !solved :)
!solved