Commit 96b254489af438c4aae737106577ef927bef5efd

Con Kolivas 2014-03-11T00:24:15

Avoid a memory leak by reusing the ntime field when rolling stratum work.

diff --git a/cgminer.c b/cgminer.c
index f16d879..2370b6a 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3709,7 +3709,17 @@ static inline bool can_roll(struct work *work)
 		work->rolls < 7000 && !stale_work(work, false));
 }
 
-static char *offset_ntime(const char *ntime, int noffset);
+/* Adjust an existing char ntime field with a relative noffset */
+static void modify_ntime(char *ntime, int noffset)
+{
+	unsigned char bin[4];
+	uint32_t h32, *be32 = (uint32_t *)bin;
+
+	hex2bin(bin, ntime, 4);
+	h32 = be32toh(*be32) + noffset;
+	*be32 = htobe32(h32);
+	__bin2hex(ntime, bin, 4);
+}
 
 void roll_work(struct work *work)
 {
@@ -3726,7 +3736,7 @@ void roll_work(struct work *work)
 	applog(LOG_DEBUG, "Successfully rolled work");
 	/* Change the ntime field if this is stratum work */
 	if (work->ntime)
-		work->ntime = offset_ntime(work->ntime, 1);
+		modify_ntime(work->ntime, 1);
 
 	/* This is now a different work item so it needs a different ID for the
 	 * hashtable */