Utterly classic C memory management error. Out-of-bounds checking would've caught this one easily.