Update reg.c

fix memory leak