Skip to content

Commit 8c24782

Browse files
committed
session BUGFIX memory leak for starting client sessions
Fixes CESNET/netopeer2#712
1 parent 3bcb8ee commit 8c24782

1 file changed

Lines changed: 30 additions & 28 deletions

File tree

src/session.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ nc_session_free(struct nc_session *session, void (*data_free)(void *))
628628
} /* else failed to lock it, too bad */
629629
}
630630

631-
if ((session->side == NC_CLIENT) && (session->status == NC_STATUS_RUNNING)) {
631+
if (session->side == NC_CLIENT) {
632632
/* cleanup message queues */
633633
/* notifications */
634634
for (contiter = session->opts.client.notifs; contiter; ) {
@@ -648,35 +648,37 @@ nc_session_free(struct nc_session *session, void (*data_free)(void *))
648648
free(p);
649649
}
650650

651-
/* send closing info to the other side */
652-
ietfnc = ly_ctx_get_module(session->ctx, "ietf-netconf", NULL, 1);
653-
if (!ietfnc) {
654-
WRN("Session %u: missing ietf-netconf schema in context, unable to send <close-session>.", session->id);
655-
} else {
656-
close_rpc = lyd_new(NULL, ietfnc, "close-session");
657-
nc_send_msg_io(session, NC_SESSION_FREE_LOCK_TIMEOUT, close_rpc);
658-
lyd_free(close_rpc);
659-
switch (nc_read_msg_poll_io(session, NC_CLOSE_REPLY_TIMEOUT, &rpl)) {
660-
case NC_MSG_REPLY:
661-
LY_TREE_FOR(rpl->child, child) {
662-
if (!strcmp(child->name, "ok") && child->ns && !strcmp(child->ns->value, NC_NS_BASE)) {
663-
break;
651+
if (session->status == NC_STATUS_RUNNING) {
652+
/* send closing info to the other side */
653+
ietfnc = ly_ctx_get_module(session->ctx, "ietf-netconf", NULL, 1);
654+
if (!ietfnc) {
655+
WRN("Session %u: missing ietf-netconf schema in context, unable to send <close-session>.", session->id);
656+
} else {
657+
close_rpc = lyd_new(NULL, ietfnc, "close-session");
658+
nc_send_msg_io(session, NC_SESSION_FREE_LOCK_TIMEOUT, close_rpc);
659+
lyd_free(close_rpc);
660+
switch (nc_read_msg_poll_io(session, NC_CLOSE_REPLY_TIMEOUT, &rpl)) {
661+
case NC_MSG_REPLY:
662+
LY_TREE_FOR(rpl->child, child) {
663+
if (!strcmp(child->name, "ok") && child->ns && !strcmp(child->ns->value, NC_NS_BASE)) {
664+
break;
665+
}
664666
}
667+
if (!child) {
668+
WRN("Session %u: the reply to <close-session> was not <ok> as expected.", session->id);
669+
}
670+
lyxml_free(session->ctx, rpl);
671+
break;
672+
case NC_MSG_WOULDBLOCK:
673+
WRN("Session %u: timeout for receiving a reply to <close-session> elapsed.", session->id);
674+
break;
675+
case NC_MSG_ERROR:
676+
ERR("Session %u: failed to receive a reply to <close-session>.", session->id);
677+
break;
678+
default:
679+
/* cannot happen */
680+
break;
665681
}
666-
if (!child) {
667-
WRN("Session %u: the reply to <close-session> was not <ok> as expected.", session->id);
668-
}
669-
lyxml_free(session->ctx, rpl);
670-
break;
671-
case NC_MSG_WOULDBLOCK:
672-
WRN("Session %u: timeout for receiving a reply to <close-session> elapsed.", session->id);
673-
break;
674-
case NC_MSG_ERROR:
675-
ERR("Session %u: failed to receive a reply to <close-session>.", session->id);
676-
break;
677-
default:
678-
/* cannot happen */
679-
break;
680682
}
681683
}
682684

0 commit comments

Comments
 (0)