From 609ebb97eaf870d555c2f242b842a18c8efc2659 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Tue, 16 Sep 2025 09:45:43 -0400 Subject: [PATCH] Fixes #1808 - Fixed a bug introduced in the last commit where a freed string could be referenced in a management query. --- src/adaptors/adaptor_listener.c | 5 ++++- src/adaptors/adaptor_listener.h | 3 ++- src/adaptors/tcp/tcp_adaptor.c | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/adaptors/adaptor_listener.c b/src/adaptors/adaptor_listener.c index 5ea6677d0..d55bf4f80 100644 --- a/src/adaptors/adaptor_listener.c +++ b/src/adaptors/adaptor_listener.c @@ -433,9 +433,12 @@ qd_listener_oper_status_t qd_adaptor_listener_oper_status(const qd_adaptor_liste char *qd_adaptor_listener_error_message(const qd_adaptor_listener_t *li) { + char *value = 0; assert(li); sys_mutex_lock((sys_mutex_t *) &li->lock); - char *value = li->error_message; + if (!!li->error_message) { + value = qd_strdup(li->error_message); + } sys_mutex_unlock((sys_mutex_t *) &li->lock); return value; } diff --git a/src/adaptors/adaptor_listener.h b/src/adaptors/adaptor_listener.h index 392880908..8bc1050de 100644 --- a/src/adaptors/adaptor_listener.h +++ b/src/adaptors/adaptor_listener.h @@ -65,7 +65,8 @@ void qd_adaptor_listener_close(qd_adaptor_listener_t *listener); // qd_listener_oper_status_t qd_adaptor_listener_oper_status(const qd_adaptor_listener_t *listener); -// Get the error string from the listener +// Get the error string from the listener - The returned string (if not NULL) has been allocated and must +// be freed by the caller. // char *qd_adaptor_listener_error_message(const qd_adaptor_listener_t *listener); diff --git a/src/adaptors/tcp/tcp_adaptor.c b/src/adaptors/tcp/tcp_adaptor.c index 6d4518b74..5dd711f33 100644 --- a/src/adaptors/tcp/tcp_adaptor.c +++ b/src/adaptors/tcp/tcp_adaptor.c @@ -2563,9 +2563,11 @@ QD_EXPORT qd_error_t qd_entity_refresh_tcpListener(qd_entity_t* entity, void *im && qd_entity_set_string(entity, "operStatus", os == QD_LISTENER_OPER_UP ? "up" : "down") == 0 && qd_entity_set_string(entity, "connectionMsg", msg ? msg : "") == 0) { + free(msg); return QD_ERROR_NONE; } + free(msg); return qd_error_code(); }