Hello Mike and thank you for taking a look.
Are you sure you want to try and write OOM-safe software? I know from experience that trying to handle NULL returns from malloc is insanely difficult to do correctly, almost no software these days even tries. Aborting the program if malloc returns NULL is invariably the right decision.
I don't know about other systems but Linux has an OOM killer that makes checking malloc redundant anyway. However, I'm adding checks for the sake of better software regardless. It's not hard to add these checks. Testing them is more difficult. Handling OOM conditions is more important when you are dealing with embedded systems and various low memory environments, so if ever the ode was to be used for these applications it would become more useful.
Also casting pointers to integers like that is likely to cause issues, which is why the compiler is warning you about it.
The compiler is not warning about casting pointers to integers, it's warning about casting a pointer to an integer of a different size. This is not a problem in this case but it doesn't matter since I'm changing my code to use void * instead.
Don't disable compiler warnings! They are there to help you.
Warnings are not necessarily problems. I could perhaps use GCC diagnostic ignored on certain files to avoid making errors ignored for all files.
The valgrind stack trace doesn't match the code on github, by the way, so if you're asking for help there you'd need to post one with fresh line numbers.
OK I'll fix that.
The code in that part of the file is very hard to read. I strongly recommend you use structs to avoid code like this:
// Checksum
memcpy(peer->sendingHeader + 20, toSend->checksum, 4);
+ 20 here is a magic number, it's not needed because the message headers have a predictable layout anyway so you could just cast the entire header to a struct and then use real identifiers.
I'll add an enum for the offsets, but I can't use a struct since this data is to be passed through the network.
Also, try to avoid redefining the language. Here:
// Need to send the header
if (NOT peer->messageSent) {
// Create header
peer->sendingHeader = malloc(24);
peer->messageSent looks like it's being treated as a boolean (i assume that NOT is defined to be !) but then later on it's treated as if it was an int. If it's a number it's better to write out the integer comparison explicitly.
I have the habit of using !/NOT (I've used NOT since I always overlook !) to mean == 0. I can see why that may be misleading. It will take a while to convert all instances of that, but I'll add an issue on github to record that.