diff --git a/networktable.c b/networktable.c index 5d47f4f0e..d5817f9ca 100644 --- a/networktable.c +++ b/networktable.c @@ -116,7 +116,6 @@ void parse_arp_cache(void) // unknown (only DNS requesting clients do this) lock_shm(); int clientID = findClientID(ip, false); - unlock_shm(); // This client is known (by its IP address) to pihole-FTL if // findClientID() returned a non-negative index @@ -177,6 +176,8 @@ void parse_arp_cache(void) // else: // Device in database but not known to Pi-hole: No action required + unlock_shm(); + // Count number of processed ARP cache entries entries++; } diff --git a/resolve.c b/resolve.c index 5cfdab1bd..1f717b704 100644 --- a/resolve.c +++ b/resolve.c @@ -66,10 +66,11 @@ static char *resolveHostname(const char *addr) // Resolve upstream destination host names static size_t resolveAndAddHostname(size_t ippos, size_t oldnamepos) { - // Get IP and host name strings + // Get IP and host name strings. They are cloned in case shared memory is + // resized before the next lock lock_shm(); - const char* ipaddr = getstr(ippos); - const char* oldname = getstr(oldnamepos); + char* ipaddr = strdup(getstr(ippos)); + char* oldname = strdup(getstr(oldnamepos)); unlock_shm(); // Important: Don't hold a lock while resolving as the main thread @@ -86,6 +87,8 @@ static size_t resolveAndAddHostname(size_t ippos, size_t oldnamepos) // newname has already been checked against NULL // so we can safely free it free(newname); + free(ipaddr); + free(oldname); unlock_shm(); return newnamepos; } @@ -95,6 +98,9 @@ static size_t resolveAndAddHostname(size_t ippos, size_t oldnamepos) logg("Not adding \"%s\" to buffer (unchanged)", oldname); } + free(ipaddr); + free(oldname); + // Not changed, return old namepos return oldnamepos; }