Added valgrind memory leak tests for backend. Fixed some minor leaks and file descriptor closes.
This commit is contained in:
parent
add43d250d
commit
4c0b412e9f
34 changed files with 318 additions and 382 deletions
|
|
@ -83,8 +83,10 @@ backend_terminate(clicon_handle h)
|
|||
{
|
||||
yang_spec *yspec;
|
||||
char *pidfile = clicon_backend_pidfile(h);
|
||||
int sockfamily = clicon_sock_family(h);
|
||||
char *sockpath = clicon_sock(h);
|
||||
cxobj *x;
|
||||
struct stat st;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
if ((yspec = clicon_dbspec_yang(h)) != NULL)
|
||||
|
|
@ -99,10 +101,12 @@ backend_terminate(clicon_handle h)
|
|||
clixon_plugin_exit(h);
|
||||
/* Delete all backend plugin RPC callbacks */
|
||||
rpc_callback_delete_all();
|
||||
|
||||
if (pidfile)
|
||||
unlink(pidfile);
|
||||
if (sockpath)
|
||||
unlink(sockpath);
|
||||
if (sockfamily==AF_UNIX && lstat(sockpath, &st) == 0)
|
||||
unlink(sockpath);
|
||||
|
||||
xmldb_plugin_unload(h); /* unload storage plugin */
|
||||
backend_handle_exit(h); /* Also deletes streams. Cannot use h after this. */
|
||||
event_exit();
|
||||
|
|
@ -203,9 +207,12 @@ db_merge(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Create backend server socket and register callback
|
||||
* @param[in] h Clicon handle
|
||||
* @retval s Server socket file descriptor (see socket(2))
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
server_socket(clicon_handle h)
|
||||
backend_server_socket(clicon_handle h)
|
||||
{
|
||||
int ss;
|
||||
|
||||
|
|
@ -571,6 +578,7 @@ main(int argc,
|
|||
yang_spec *yspec = NULL;
|
||||
yang_spec *yspecfg = NULL; /* For config XXX clixon bug */
|
||||
char *str;
|
||||
int ss = -1; /* server socket */
|
||||
|
||||
/* In the startup, logs to stderr & syslog and debug flag set later */
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
|
|
@ -924,7 +932,7 @@ main(int argc,
|
|||
}
|
||||
|
||||
/* Initialize server socket */
|
||||
if (server_socket(h) < 0)
|
||||
if ((ss = backend_server_socket(h)) < 0)
|
||||
goto done;
|
||||
|
||||
if (debug)
|
||||
|
|
@ -937,6 +945,8 @@ main(int argc,
|
|||
retval = 0;
|
||||
done:
|
||||
clicon_log(LOG_NOTICE, "%s: %u Terminated retval:%d", __PROGRAM__, getpid(), retval);
|
||||
if (ss != -1)
|
||||
close(ss);
|
||||
backend_terminate(h); /* Cannot use h after this */
|
||||
|
||||
return retval;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,13 @@
|
|||
#include "backend_client.h"
|
||||
#include "backend_handle.h"
|
||||
|
||||
/*! Open an INET stream socket and bind it to a file descriptor
|
||||
*
|
||||
o * @param[in] h Clicon handle
|
||||
* @param[in] dst IPv4 address (see inet_pton(3))
|
||||
* @retval s Socket file descriptor (see socket(2))
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
config_socket_init_ipv4(clicon_handle h,
|
||||
char *dst)
|
||||
|
|
@ -112,10 +119,14 @@ config_socket_init_ipv4(clicon_handle h,
|
|||
return -1;
|
||||
}
|
||||
|
||||
/*! Open a socket and bind it to a file descriptor
|
||||
/*! Open a UNIX domain socket and bind it to a file descriptor
|
||||
*
|
||||
* The socket is accessed via CLICON_SOCK option, has 770 permissions
|
||||
* and group according to CLICON_SOCK_GROUP option.
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] sock Unix file-system path
|
||||
* @retval s Socket file descriptor (see socket(2))
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
config_socket_init_unix(clicon_handle h,
|
||||
|
|
@ -175,10 +186,16 @@ config_socket_init_unix(clicon_handle h,
|
|||
return -1;
|
||||
}
|
||||
|
||||
/*! Open backend socket, the one clients send requests to, either ip or unix
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @retval s Socket file descriptor (see socket(2))
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
backend_socket_init(clicon_handle h)
|
||||
{
|
||||
char *sock;
|
||||
char *sock; /* unix path or ip address string */
|
||||
|
||||
if ((sock = clicon_sock(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
|
||||
|
|
@ -191,8 +208,12 @@ backend_socket_init(clicon_handle h)
|
|||
case AF_INET:
|
||||
return config_socket_init_ipv4(h, sock);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_UNIX, EINVAL, "No such address family: %d",
|
||||
clicon_sock_family(h));
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! Accept new socket client
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue