error detection and memory leaks in c example