Commit a0c16041 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Fixed memory leak. Added dump_allocated_connections().

parent 6e586fdf
......@@ -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;
}
......@@ -78,7 +82,7 @@ new_client(void)
c->ena_level = 0;
c->username = EMPTY_STRING;
c->kill_me = FALSE;
return c;
}
......@@ -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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment