r/cprogramming • u/frizzy67 • Jun 19 '26
A shi**y group chat application, my first C project
https://github.com/ievanpoikka/ChatexI'm fairly new to the world of C and application programming. I am trying to learn more about how network programming and multithreading works in C (and in general) so I made this hella buggy group chat application (inspired from https://github.com/masoudy/CSocket )
It has quite a few bugs, sometimes the server randomly crashes with a SIGPIPE, sometimes it refuses a client connection when the usernames have a few characters in common in the beginning. The client bugs out when server refuses the connection and prints random amounts of "You [name]: " strings before exiting.
I'm pretty sure there are a few memory leaks but I'm not exactly sure how to test for them😭
Can you guys please critique my code give me an honest opinion...? I will really appreciate it, thanks!
Edit: I had merged the multithreading branch but forgot to push it to github, my bad 😭, just did it now, I'm sorry for making you guys review my old code
4
u/Immediate-Food8050 Jun 19 '26
You can test for memory leaks using valgrind
4
u/ByMeno Jun 19 '26
Most of the time I get sigpipe its about a closed fd which is sockets in this case but might file too I didn't checked that much asan for memory corruption ubsan for undefined behavior and valgrind for memory leak and the namings of the functions feel like a go's naming
3
u/Honest_Medium_2872 Jun 21 '26
Some feedback:
This is much faster allocation wise and a common pattern in C; The only caveat is you have to remember when the stack gets clean - at the end of a function, the pointer you created with &as is invalid. For global objects that exist the entire lifetime of the program this is advantageous, for temporary values this is advantageous. There are other caveats but this gets you thinking of object/memory lifetimes and less like object oriented memory managed languages.