Skip to content
Snippets Groups Projects
Commit a0c16041 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Fixed memory leak. Added dump_allocated_connections().

parent 6e586fdf
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@
#include "internal-connections.h"
#include "lyskomd.h"
#include "config.h"
#include "log.h"
INTERNAL Connection *all_connections = NULL;
......@@ -29,6 +30,8 @@ INTERNAL const Connection EMPTY_CONNECTION =
NULL_CONF_TYPE_i, EMPTY_STRING_i, 0, FALSE, NO_TIME,
0, FALSE});
static int no_of_allocated_connections = 0;
INTERNAL Connection *
alloc_connection(void)
{
......@@ -36,6 +39,7 @@ alloc_connection(void)
res = smalloc ( sizeof(Connection) );
*res = EMPTY_CONNECTION;
++no_of_allocated_connections;
return res;
}
......@@ -117,7 +121,29 @@ kill_client(Connection *cp)
last_conn = NULL;
cp->magic = CONN_MAGIC_FREE;
s_clear(&cp->unparsed);
s_clear(&cp->what_am_i_doing);
s_clear(&cp->username);
s_clear(&cp->hostname);
if ( cp->mux != NULL )
{
log("kill_client(): client %d has mux != NULL.\n",
cp->session_no);
}
if ( !s_empty(cp->c_string0) || !s_empty(cp->c_string1)
|| !s_empty(cp->string0) )
{
log("kill_client(): unexpected string remains.\n");
}
if ( cp->c_misc_info_p != NULL || cp->c_local_text_no_p != NULL )
log("kill_client(): unexpected remaining data.\n");
sfree(cp);
--no_of_allocated_connections;
}
#ifdef DEFENSIVE_CHECKS
......@@ -201,3 +227,10 @@ traverse_connections (Session_no session_no)
else
return prev->next->session_no;
}
void
dump_allocated_connections(FILE *fp)
{
fprintf(fp, "---" __FILE__ ":\n\tConnections: %d\n",
no_of_allocated_connections);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment