Skip to content

Commit 5a2c716

Browse files
committed
client session BUGFIX memory leak
Also, docs updated and reply (even in case of invalid msgid) is always returned.
1 parent 2209191 commit 5a2c716

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/session_client.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@ nc_client_destroy(void)
20542054
API NC_MSG_TYPE
20552055
nc_recv_reply(struct nc_session *session, struct nc_rpc *rpc, uint64_t msgid, int timeout, int parseroptions, struct nc_reply **reply)
20562056
{
2057-
struct lyxml_elem *xml;
2057+
struct lyxml_elem *xml = NULL;
20582058
NC_MSG_TYPE msgtype = 0; /* NC_MSG_ERROR */
20592059

20602060
if (!session) {
@@ -2063,6 +2063,9 @@ nc_recv_reply(struct nc_session *session, struct nc_rpc *rpc, uint64_t msgid, in
20632063
} else if (!rpc) {
20642064
ERRARG("rpc");
20652065
return NC_MSG_ERROR;
2066+
} else if (!msgid) {
2067+
ERRARG("msgid");
2068+
return NC_MSG_ERROR;
20662069
} else if (!reply) {
20672070
ERRARG("reply");
20682071
return NC_MSG_ERROR;
@@ -2083,13 +2086,15 @@ nc_recv_reply(struct nc_session *session, struct nc_rpc *rpc, uint64_t msgid, in
20832086

20842087
msgtype = get_msg(session, timeout, msgid, &xml);
20852088

2086-
if (msgtype == NC_MSG_REPLY) {
2089+
if ((msgtype == NC_MSG_REPLY) || (msgtype == NC_MSG_REPLY_ERR_MSGID)) {
20872090
*reply = parse_reply(session->ctx, xml, rpc, parseroptions);
2088-
lyxml_free(session->ctx, xml);
2091+
lyxml_free_withsiblings(session->ctx, xml);
2092+
xml = NULL;
20892093
if (!(*reply)) {
20902094
return NC_MSG_ERROR;
20912095
}
20922096
}
2097+
assert(!xml);
20932098

20942099
return msgtype;
20952100
}

src/session_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ int nc_session_ntf_thread_running(const struct nc_session *session);
566566
* waiting and 0 for immediate return if data are not available on the wire.
567567
* @param[in] parseroptions libyang parseroptions flags, do not set the data type, it is set
568568
* internally. \b LYD_OPT_DESTRUCT and \b LYD_OPT_NOSIBLINGS is ignored.
569-
* @param[out] reply Resulting object of NETCONF RPC reply.
569+
* @param[out] reply Resulting object of NETCONF RPC reply. Set only on #NC_MSG_REPLY and #NC_MSG_REPLY_ERR_MSGID return.
570570
* @return #NC_MSG_REPLY for success,
571571
* #NC_MSG_WOULDBLOCK if \p timeout has elapsed,
572572
* #NC_MSG_ERROR if reading has failed,

0 commit comments

Comments
 (0)