CLEANUP: fixed some usages of realloc leading to memory leak

Changed all the cases where the pointer passed to realloc is overwritten
by the pointer returned by realloc. The new function my_realloc2 has
been used except in function register_name. If register_name fails to
add a new variable because of an "out of memory" error, all the existing
variables remain valid. If we had used my_realloc2, the array of variables
would have been freed.
diff --git a/src/chunk.c b/src/chunk.c
index e251107..7134fea 100644
--- a/src/chunk.c
+++ b/src/chunk.c
@@ -17,6 +17,7 @@
 
 #include <common/config.h>
 #include <common/chunk.h>
+#include <common/standard.h>
 
 /* trash chunks used for various conversions */
 static struct chunk *trash_chunk;
@@ -60,8 +61,8 @@
 int alloc_trash_buffers(int bufsize)
 {
 	trash_size = bufsize;
-	trash_buf1 = (char *)realloc(trash_buf1, bufsize);
-	trash_buf2 = (char *)realloc(trash_buf2, bufsize);
+	trash_buf1 = (char *)my_realloc2(trash_buf1, bufsize);
+	trash_buf2 = (char *)my_realloc2(trash_buf2, bufsize);
 	return trash_buf1 && trash_buf2;
 }