From 9bf927a496e5aead1d9669c58887bec67d85ed6d Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 4 Sep 2014 18:18:53 +0200 Subject: [PATCH] hashlog: fix erase while iterating exception --- hashlog.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hashlog.cpp b/hashlog.cpp index 06720b0..811fed2 100644 --- a/hashlog.cpp +++ b/hashlog.cpp @@ -164,9 +164,9 @@ extern "C" void hashlog_purge_job(char* jobid) while (i != tlastshares.end()) { if ((keypfx & i->first) == keypfx) { deleted++; - tlastshares.erase(i); + tlastshares.erase(i++); } - i++; + else ++i; } if (opt_debug && deleted) { applog(LOG_DEBUG, "hashlog: purge job %s, del %d/%d", jobid, deleted, sz); @@ -185,9 +185,9 @@ extern "C" void hashlog_purge_old(void) while (i != tlastshares.end()) { if ((now - i->second.tm_sent) > LOG_PURGE_TIMEOUT) { deleted++; - tlastshares.erase(i); + tlastshares.erase(i++); } - i++; + else ++i; } if (opt_debug && deleted) { applog(LOG_DEBUG, "hashlog: %d/%d purged", deleted, sz);