Skip to content

Commit a6d6aa0

Browse files
committed
Fixes #1808 - Fixed a bug introduced in the last commit where a freed string could be referenced in a management query.
1 parent 71a346a commit a6d6aa0

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/adaptors/adaptor_listener.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,12 @@ qd_listener_oper_status_t qd_adaptor_listener_oper_status(const qd_adaptor_liste
433433

434434
char *qd_adaptor_listener_error_message(const qd_adaptor_listener_t *li)
435435
{
436+
char *value = 0;
436437
assert(li);
437438
sys_mutex_lock((sys_mutex_t *) &li->lock);
438-
char *value = li->error_message;
439+
if (!!li->error_message) {
440+
value = qd_strdup(li->error_message);
441+
}
439442
sys_mutex_unlock((sys_mutex_t *) &li->lock);
440443
return value;
441444
}

src/adaptors/adaptor_listener.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void qd_adaptor_listener_close(qd_adaptor_listener_t *listener);
6565
//
6666
qd_listener_oper_status_t qd_adaptor_listener_oper_status(const qd_adaptor_listener_t *listener);
6767

68-
// Get the error string from the listener
68+
// Get the error string from the listener - The returned string (if not NULL) has been allocated and must
69+
// be freed by the caller.
6970
//
7071
char *qd_adaptor_listener_error_message(const qd_adaptor_listener_t *listener);
7172

src/adaptors/tcp/tcp_adaptor.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,9 +2563,11 @@ QD_EXPORT qd_error_t qd_entity_refresh_tcpListener(qd_entity_t* entity, void *im
25632563
&& qd_entity_set_string(entity, "operStatus", os == QD_LISTENER_OPER_UP ? "up" : "down") == 0
25642564
&& qd_entity_set_string(entity, "connectionMsg", msg ? msg : "") == 0)
25652565
{
2566+
free(msg);
25662567
return QD_ERROR_NONE;
25672568
}
25682569

2570+
free(msg);
25692571
return qd_error_code();
25702572
}
25712573

0 commit comments

Comments
 (0)