From 600f0616f61156c41b7f254b941b4c4cfd612e28 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sun, 17 Apr 2022 13:21:05 +0200 Subject: [PATCH] Memory leak/err in notification when closing down test: restconf notification chunked framing update --- apps/netconf/netconf_rpc.c | 13 +++++++++---- lib/src/clixon_netconf_lib.c | 2 +- test/test_restconf_notifications.sh | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index 33fe9065..f789f2e5 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -444,7 +444,7 @@ netconf_notification_cb(int s, struct clicon_msg *reply = NULL; int eof; int retval = -1; - cbuf *cb; + cbuf *cb = NULL; cxobj *xn = NULL; /* event xml */ cxobj *xt = NULL; /* top xml */ clicon_handle h = (clicon_handle)arg; @@ -485,17 +485,22 @@ netconf_notification_cb(int s, goto done; /* Send it to listening client on stdout */ if (netconf_output_encap(clicon_option_int(h, "netconf-framing"), cb) < 0){ - cbuf_free(cb); goto done; } - if (netconf_output(1, cb, "notification") < 0) + if (netconf_output(1, cb, "notification") < 0){ + clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); + close(s); + errno = ESHUTDOWN; + clixon_event_unreg_fd(s, netconf_notification_cb); goto done; + } fflush(stdout); - cbuf_free(cb); ok: retval = 0; done: clicon_debug(1, "%s %d", __FUNCTION__, retval); + if (cb) + cbuf_free(cb); if (nsc) xml_nsctx_free(nsc); if (xt != NULL) diff --git a/lib/src/clixon_netconf_lib.c b/lib/src/clixon_netconf_lib.c index 526e7167..20fc6cb9 100644 --- a/lib/src/clixon_netconf_lib.c +++ b/lib/src/clixon_netconf_lib.c @@ -2003,7 +2003,7 @@ netconf_output(int s, } if (write(s, buf, len) < 0){ if (errno == EPIPE) - ; + clicon_debug(1, "%s write err SIGPIPE", __FUNCTION__); else clicon_log(LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno)); goto done; diff --git a/test/test_restconf_notifications.sh b/test/test_restconf_notifications.sh index de5441fa..4cb1a9e0 100755 --- a/test/test_restconf_notifications.sh +++ b/test/test_restconf_notifications.sh @@ -55,7 +55,7 @@ cat < $cfg /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/$APPNAME/backend example_backend.so$ - $dir/restconf.pidfile + /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli @@ -140,7 +140,7 @@ new "wait restconf" wait_restconf new "netconf event stream discovery RFC8040 Sec 6.2" -expecteof "$clixon_netconf -D $DBG -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "EXAMPLEExample event streamtruexmlhttps://localhost/streams/EXAMPLE]]>]]>" +expecteof_netconf "$clixon_netconf -D $DBG -qf $cfg" 0 "$DEFAULTHELLO" "" "" "EXAMPLEExample event streamtruexmlhttps://localhost/streams/EXAMPLE" # # 1.2 Netconf stream subscription