From 8d1ab7485179928e93bd147e46d098dc6bfeb03d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 24 Dec 2016 11:41:29 +1100 Subject: [PATCH] Only update sockaddr and port if they've changed. in extract_sockaddr --- src/libckpool.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index 51fe21e0..20c64370 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -502,12 +502,20 @@ bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port) * This function may be called with sockaddr_* already set as it may * be getting updated so we need to free the old entries safely. * Use a temporary variable so they never dereference */ - tmp = *sockaddr_port; - *sockaddr_port = port; - free(tmp); - tmp = *sockaddr_url; - *sockaddr_url = url_address; - free(tmp); + if (*sockaddr_port && !safecmp(*sockaddr_port, port)) + free(port); + else { + tmp = *sockaddr_port; + *sockaddr_port = port; + free(tmp); + } + if (*sockaddr_url && !safecmp(*sockaddr_url, url_address)) + free(url_address); + else { + tmp = *sockaddr_url; + *sockaddr_url = url_address; + free(tmp); + } return true; }