Baffling problem : can't find source of leaks
Hey all,
My friend and I are on an assignment for our programming school. The assignment is to create a function which will read & return lines from a file, one line per call, using a static variable. It should return NULL in case of invalid fd, or nothing more to read. It's prototyped like this :
Code:
char *get_next_line(int fd)
I was able to turn in the assignment and get full grades on the first try. My friend has failed twice already, because of supposed leaks, and we can't figure out where they're coming from.
Our school has an automated program which runs extensive tests on our own programs to grade us. It is that automated program which detects leaks. Unfortunately we have no access to the code or the files it's testing with. We can only take it at its word.
We've used two different testers made by other students, both use valgrind, we detect no leaks. One of them tests with a combination of different files (empty, empty with newline, one line, big lines, etc...), the other tests with massive randomly generated files.
We've tested with really big text files, really big non-text files (my program didn't handle binary and it passed, so it's not needed). No leaks.
We cleaned up his code (it was a bit wonky but it worked) before sending it a second time, the exact same leaks were found on the exact same tests.
I usually have a good eye for these things. I don't give up. I was 100% sure we missed something. There's no way the grading program is wrong. But I admit defeat, I have NO idea where it's going wrong. We've tested 99.9% of cases, and the grading program seems to find leaks on even the first few tests it runs (which should be basic tests).
We need help. We're completely lost here. Of all the students we've asked for help, nobody could find what was going wrong. I'm starting to believe the grading program ........ed up somewhere.
Is there anything else than valgrind which could find leaks valgrind can't?
Does anyone have any idea what kind of weird scenario could cause such a simple program to leak?
Here is the code:
get_next_line/get_next_line.c at master * m0d1nst4ll3r/get_next_line * GitHub
get_next_line/get_next_line_utils.c at master * m0d1nst4ll3r/get_next_line * GitHub
Thank you!
Edit: thinking about it, the mallocs are not all protected, but they still wouldn't cause leaks or cause any catastrophic behavior. I don't think the grading program tests that and if it did, certainly not on the first few tests.