Minefield in C with using dynamic memory allocation