diff --git a/src/ckpool.h b/src/ckpool.h index d23179f6..4d8d69c6 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -110,6 +110,11 @@ ckpool_t *global_ckp; int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); +#define ASPRINTF(strp, fmt, ...) do { \ + if (unlikely(asprintf(strp, fmt, ##__VA_ARGS__))) \ + quitfrom(1, __FILE__, __func__, __LINE__, "Failed to asprintf"); \ +} while (0) + /* Log everything to the logfile, but display warnings on the console as well */ #define LOGMSG(_loglevel, fmt, ...) do { \ if (global_ckp->loglevel >= _loglevel && fmt) { \ @@ -118,7 +123,7 @@ int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); time_t now_t; \ int LOGFD = global_ckp->logfd; \ \ - asprintf(&BUF, fmt, ##__VA_ARGS__); \ + ASPRINTF(&BUF, fmt, ##__VA_ARGS__); \ now_t = time(NULL); \ tm = localtime(&now_t); \ if (LOGFD) { \ diff --git a/src/generator.c b/src/generator.c index aa21be09..73f9cab7 100644 --- a/src/generator.c +++ b/src/generator.c @@ -658,7 +658,7 @@ static bool parse_reconnect(proxy_instance_t *proxi, json_t *val) si->url, new_url); goto out; } - asprintf(&url, "%s:%d", new_url, new_port); + ASPRINTF(&url, "%s:%d", new_url, new_port); } else url = strdup(si->url); LOGINFO("Processing reconnect request to %s", url); diff --git a/src/stratifier.c b/src/stratifier.c index bbc617b0..29fc3926 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -854,7 +854,7 @@ static void block_solve(ckpool_t *ckp) LOGWARNING("Total shares from all users: %.0f pplns window %.0f", total, window); - asprintf(&msg, "Block solved by %s after %.0f shares!", ckp->name, total); + ASPRINTF(&msg, "Block solved by %s after %.0f shares!", ckp->name, total); stratum_broadcast_message(msg); free(msg); }