Recalloc correct pointer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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);