memeory issue in forward_alg.c