Commit 8944794301dafb4287adee52aecb0713a8a18477

Con Kolivas 2014-04-14T19:51:28

Recalloc correct pointer

diff --git a/util.c b/util.c
index 17f4e61..5d9d542 100644
--- a/util.c
+++ b/util.c
@@ -1525,15 +1525,15 @@ static void clear_sock(struct pool *pool)
 }
 
 /* Realloc memory to new size and zero any extra memory added */
-void _recalloc(void *ptr, size_t old, size_t new, const char *file, const char *func, const int line)
+void _recalloc(void **ptr, size_t old, size_t new, const char *file, const char *func, const int line)
 {
 	if (new == old)
 		return;
-	ptr = realloc(ptr, new);
-	if (unlikely(!ptr))
+	*ptr = realloc(*ptr, new);
+	if (unlikely(!*ptr))
 		quitfrom(1, file, func, line, "Failed to realloc");
 	if (new > old)
-		memset(ptr + old, 0, new - old);
+		memset(*ptr + old, 0, new - old);
 }
 
 /* Make sure the pool sockbuf is large enough to cope with any coinbase size
diff --git a/util.h b/util.h
index f122983..a17df1f 100644
--- a/util.h
+++ b/util.h
@@ -137,8 +137,8 @@ int ms_tdiff(struct timeval *end, struct timeval *start);
 double tdiff(struct timeval *end, struct timeval *start);
 bool stratum_send(struct pool *pool, char *s, ssize_t len);
 bool sock_full(struct pool *pool);
-void _recalloc(void *ptr, size_t old, size_t new, const char *file, const char *func, const int line);
-#define recalloc(ptr, old, new) _recalloc(ptr, old, new, __FILE__, __func__, __LINE__)
+void _recalloc(void **ptr, size_t old, size_t new, const char *file, const char *func, const int line);
+#define recalloc(ptr, old, new) _recalloc((void *)&(ptr), old, new, __FILE__, __func__, __LINE__)
 char *recv_line(struct pool *pool);
 bool parse_method(struct pool *pool, char *s);
 bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port);