Memory leaks

This commit is contained in:
Olof hagsand 2023-02-14 16:42:30 +01:00
parent 0ef0970c04
commit 585823a609
5 changed files with 27 additions and 7 deletions

View file

@ -121,6 +121,7 @@ backend_terminate(clicon_handle h)
ys_free(yspec); ys_free(yspec);
if ((nsctx = clicon_nsctx_global_get(h)) != NULL) if ((nsctx = clicon_nsctx_global_get(h)) != NULL)
cvec_free(nsctx); cvec_free(nsctx);
clicon_data_cvec_del(h, "netconf-statistics");
if ((x = clicon_nacm_ext(h)) != NULL) if ((x = clicon_nacm_ext(h)) != NULL)
xml_free(x); xml_free(x);
if ((x = clicon_conf_xml(h)) != NULL) if ((x = clicon_conf_xml(h)) != NULL)

View file

@ -256,6 +256,7 @@ restconf_proto2str(int proto)
} }
/*! Return media_in from Content-Type, -1 if not found or unrecognized /*! Return media_in from Content-Type, -1 if not found or unrecognized
*
* @note media-type syntax does not support parameters * @note media-type syntax does not support parameters
* @see RFC7231 Sec 3.1.1.1 for media-type syntax type: * @see RFC7231 Sec 3.1.1.1 for media-type syntax type:
* media-type = type "/" subtype *( OWS ";" OWS parameter ) * media-type = type "/" subtype *( OWS ";" OWS parameter )
@ -277,6 +278,7 @@ restconf_content_type(clicon_handle h)
} }
/*! Translate http header by capitalizing, prepend w HTTP_ and - -> _ /*! Translate http header by capitalizing, prepend w HTTP_ and - -> _
*
* Example: Host -> HTTP_HOST * Example: Host -> HTTP_HOST
*/ */
int int
@ -316,6 +318,7 @@ restconf_convert_hdr(clicon_handle h,
} }
/*! Parse a cookie string and return value of cookie attribute /*! Parse a cookie string and return value of cookie attribute
*
* @param[in] cookiestr cookie string according to rfc6265 (modified) * @param[in] cookiestr cookie string according to rfc6265 (modified)
* @param[in] attribute cookie attribute * @param[in] attribute cookie attribute
* @param[out] val malloced cookie value, free with free() * @param[out] val malloced cookie value, free with free()
@ -343,6 +346,7 @@ get_user_cookie(char *cookiestr,
} }
/*! Clean and close all state of restconf process (but dont exit). /*! Clean and close all state of restconf process (but dont exit).
*
* Cannot use h after this * Cannot use h after this
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
@ -486,7 +490,7 @@ restconf_insert_attributes(cxobj *xdata,
} }
/*! Callback for yang extensions ietf-restconf:yang-data /*! Callback for yang extensions ietf-restconf:yang-data
* @see ietf-restconf.yang *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] yext Yang node of extension * @param[in] yext Yang node of extension
* @param[in] ys Yang node of (unknown) statement belonging to extension * @param[in] ys Yang node of (unknown) statement belonging to extension
@ -499,6 +503,7 @@ restconf_insert_attributes(cxobj *xdata,
* - The available identity values for any 'identityref' * - The available identity values for any 'identityref'
* leaf or leaf-list nodes are limited to the module containing this extension statement and * leaf or leaf-list nodes are limited to the module containing this extension statement and
* the modules imported into that module. * the modules imported into that module.
* @see ietf-restconf.yang
*/ */
int int
restconf_main_extension_cb(clicon_handle h, restconf_main_extension_cb(clicon_handle h,
@ -560,6 +565,7 @@ restconf_uripath(clicon_handle h)
} }
/*! Drop privileges from root to user (or already at user) /*! Drop privileges from root to user (or already at user)
*
* @param[in] h Clicon handle * @param[in] h Clicon handle
* Group set to CLICON_SOCK_GROUP to communicate with backend * Group set to CLICON_SOCK_GROUP to communicate with backend
*/ */
@ -642,9 +648,9 @@ restconf_drop_privileges(clicon_handle h)
* @param[in] req Generic Www handle (can be part of clixon handle) * @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] pretty Pretty-print * @param[in] pretty Pretty-print
* @param[in] media_out Restconf output media * @param[in] media_out Restconf output media
* @retval -1 Error
* @retval 0 Not authenticated
* @retval 1 Authenticated * @retval 1 Authenticated
* @retval 0 Not authenticated
* @retval -1 Error
*/ */
int int
restconf_authentication_cb(clicon_handle h, restconf_authentication_cb(clicon_handle h,
@ -727,11 +733,12 @@ restconf_authentication_cb(clicon_handle h,
} }
/*! Basic config init, set auth-type, pretty, etc /*! Basic config init, set auth-type, pretty, etc
*
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] xrestconf XML config containing clixon-restconf top-level * @param[in] xrestconf XML config containing clixon-restconf top-level
* @retval -1 Error
* @retval 0 Restconf is disable
* @retval 1 OK * @retval 1 OK
* @retval 0 Restconf is disable
* @retval -1 Error
*/ */
int int
restconf_config_init(clicon_handle h, restconf_config_init(clicon_handle h,
@ -809,7 +816,6 @@ restconf_config_init(clicon_handle h,
goto done; goto done;
} }
/*! Create and bind restconf socket /*! Create and bind restconf socket
* *
* @param[in] netns0 Network namespace, special value "default" is same as NULL * @param[in] netns0 Network namespace, special value "default" is same as NULL

View file

@ -180,6 +180,7 @@
static int session_id_context = 1; static int session_id_context = 1;
/*! Set restconf native handle /*! Set restconf native handle
*
* @param[in] h Clicon handle * @param[in] h Clicon handle
* @param[in] rh Restconf native handle (malloced pointer) * @param[in] rh Restconf native handle (malloced pointer)
*/ */
@ -321,6 +322,7 @@ alpn_proto_dump(const char *label,
} }
/*! Application-layer Protocol Negotiation (alpn) callback /*! Application-layer Protocol Negotiation (alpn) callback
*
* The value of the out, outlen vector should be set to the value of a single protocol selected from * The value of the out, outlen vector should be set to the value of a single protocol selected from
* the in, inlen vector. The out buffer may point directly into in, or to a buffer that outlives the * the in, inlen vector. The out buffer may point directly into in, or to a buffer that outlives the
* handshake. * handshake.
@ -524,6 +526,7 @@ restconf_checkcert_file(cxobj *xrestconf,
} }
/*! Accept new socket client /*! Accept new socket client
*
* @param[in] fd Socket (unix or ip) * @param[in] fd Socket (unix or ip)
* @param[in] arg typecast clicon_handle * @param[in] arg typecast clicon_handle
* @see openssl_init_socket where this callback is registered * @see openssl_init_socket where this callback is registered
@ -565,6 +568,10 @@ restconf_accept_client(int fd,
break; break;
} }
} }
if (rsock->rs_from_addr != NULL){
free(rsock->rs_from_addr);
rsock->rs_from_addr = NULL;
}
if ((rsock->rs_from_addr = calloc(INET6_ADDRSTRLEN, 1)) == NULL){ if ((rsock->rs_from_addr = calloc(INET6_ADDRSTRLEN, 1)) == NULL){
clicon_err(OE_UNIX, errno, "calloc"); clicon_err(OE_UNIX, errno, "calloc");
goto done; goto done;
@ -635,6 +642,7 @@ restconf_native_terminate(clicon_handle h)
} }
/*! Query backend of config. /*! Query backend of config.
*
* Loop to wait for backend starting, try again if not done * Loop to wait for backend starting, try again if not done
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[out] xrestconf XML restconf config, malloced (if retval = 1) * @param[out] xrestconf XML restconf config, malloced (if retval = 1)
@ -705,6 +713,7 @@ restconf_clixon_backend(clicon_handle h,
} }
/*! Per-socket openssl inits /*! Per-socket openssl inits
*
* @param[in] h Clicon handle * @param[in] h Clicon handle
* @param[in] xs XML config of single restconf socket * @param[in] xs XML config of single restconf socket
* @param[in] nsc Namespace context * @param[in] nsc Namespace context
@ -893,6 +902,7 @@ restconf_openssl_init(clicon_handle h,
} }
/*! Read restconf from config /*! Read restconf from config
*
* After SEVERAL iterations the code now does as follows: * After SEVERAL iterations the code now does as follows:
* - init clixon * - init clixon
* - look for local config (in clixon-config file) * - look for local config (in clixon-config file)
@ -1069,6 +1079,7 @@ restconf_clixon_init(clicon_handle h,
} }
/*! Signal terminates process /*! Signal terminates process
*
* Just set exit flag for proper exit in event loop * Just set exit flag for proper exit in event loop
*/ */
static void static void
@ -1088,6 +1099,7 @@ restconf_sig_term(int arg)
} }
/*! Usage help routine /*! Usage help routine
*
* @param[in] argv0 command line * @param[in] argv0 command line
* @param[in] h Clicon handle * @param[in] h Clicon handle
*/ */

View file

@ -155,7 +155,7 @@ typedef struct restconf_socket{
* Set in restconf_callhome_cb * Set in restconf_callhome_cb
*/ */
restconf_conn *rs_conns; /* List of transient connect sockets */ restconf_conn *rs_conns; /* List of transient connect sockets */
char *rs_from_addr; /* From IP address as seen by accept */ char *rs_from_addr; /* From IP address as seen by accept (mv to rc?) */
} restconf_socket; } restconf_socket;

View file

@ -130,6 +130,7 @@ case $release in
;; ;;
freebsd) freebsd)
# packages for building # packages for building
$sshcmd sudo pkg upgrade -y
$sshcmd sudo pkg install -y git gmake bash $sshcmd sudo pkg install -y git gmake bash
# cligen # cligen
$sshcmd sudo pkg install -y bison flex $sshcmd sudo pkg install -y bison flex