Browse Source

Kill some memleaks

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent
commit
721cb88985
  1. 1
      src/actions_lua.c
  2. 1
      src/condition.c
  3. 63
      src/config_lua.c
  4. 24
      src/plugin.c
  5. 1
      src/plugin.h
  6. 4
      src/plugin_core.c
  7. 15
      src/server.c
  8. 2
      src/worker.c

1
src/actions_lua.c

@ -32,7 +32,6 @@ int lua_push_action(server *srv, lua_State *L, action *a) {
action **pa;
pa = (action**) lua_newuserdata(L, sizeof(action*));
action_acquire(a);
*pa = a;
if (luaL_newmetatable(L, LUA_ACTION)) {

1
src/condition.c

@ -172,6 +172,7 @@ condition* condition_new_int(server *srv, comp_operator_t op, condition_lvalue *
static void condition_free(condition *c) {
condition_lvalue_release(c->lvalue);
switch (c->rvalue.type) {
case COND_VALUE_INT:
/* nothing to free */

63
src/config_lua.c

@ -80,7 +80,7 @@ static int handle_server_action(lua_State *L) {
opt = lua_params_to_option(srv, L);
TRACE(srv, "%s", "Creating action");
/* TRACE(srv, "%s", "Creating action"); */
if (NULL == (a = sa->create_action(srv, sa->p, opt))) {
lua_pushstring(L, "creating action failed");
@ -124,62 +124,6 @@ static int wrap_server_setup(server *srv, lua_State *L, gpointer ss) {
return 1;
}
static action* action_from_lua(server *srv, lua_State *L) {
const gchar *optname;
option *value;
action *a;
optname = luaL_checklstring(L, -2, NULL);
if (!optname) {
lua_pushstring(L, "wrong config argument, expected string");
lua_error(L);
}
value = option_from_lua(srv, L);
if (!value) {
lua_pushstring(L, "missing config value");
lua_error(L);
}
a = option_action(srv, optname, value);
if (!a) {
option_free(value);
lua_pushstring(L, "couldn't create action from setting");
lua_error(L);
}
return a;
}
static int handle_option(lua_State *L) {
server *srv;
action *a, *suba;
srv = (server*) lua_touserdata(L, lua_upvalueindex(1));
switch (lua_gettop(L)) {
case 1:
if (!lua_istable(L, 1)) {
lua_pushstring(L, "wrong config argument, expected table");
lua_error(L);
}
a = action_new_list();
lua_push_action(srv, L, a);
lua_insert(L, 1);
lua_pushnil(L);
while (lua_next(L, 2) != 0) {
suba = action_from_lua(srv, L);
g_array_append_val(a->value.list, suba);
lua_pop(L, 1);
}
lua_pop(L, 1);
return 1;
case 2:
a = action_from_lua(srv, L);
return lua_push_action(srv, L, a);
default:
lua_pushstring(L, "wrong count of arguments to config()");
lua_error(L);
}
return 0;
}
gboolean config_lua_load(server *srv, const gchar *filename) {
lua_State *L;
@ -199,10 +143,6 @@ gboolean config_lua_load(server *srv, const gchar *filename) {
publish_str_hash(srv, L, srv->actions, wrap_server_action);
lua_setfield(L, LUA_GLOBALSINDEX, "action");
lua_pushlightuserdata(L, srv);
lua_pushcclosure(L, handle_option, 1);
lua_setfield(L, LUA_GLOBALSINDEX, "option");
lua_push_lvalues_dict(srv, L);
if (lua_pcall(L, 0, 1, 0)) {
@ -214,6 +154,7 @@ gboolean config_lua_load(server *srv, const gchar *filename) {
lua_getfield(L, LUA_GLOBALSINDEX, "actions");
srv->mainaction = lua_get_action(L, -1);
action_acquire(srv->mainaction);
lua_pop(L, 1);
assert(lua_gettop(L) == 0);

24
src/plugin.c

@ -63,6 +63,30 @@ void plugin_free(server *srv, plugin *p) {
g_slice_free(plugin, p);
}
void server_plugins_free(server *srv) {
if (g_atomic_int_get(&srv->state) == SERVER_RUNNING) {
ERROR(srv, "%s", "Cannot free plugins while server is running");
return;
}
gpointer key, value;
GHashTableIter i;
g_hash_table_iter_init(&i, srv->plugins);
while (g_hash_table_iter_next(&i, &key, &value)) {
plugin *p = (plugin*) value;
plugin_free_options(srv, p);
plugin_free_actions(srv, p);
plugin_free_setups(srv, p);
g_slice_free(plugin, p);
}
g_hash_table_destroy(srv->plugins);
g_hash_table_destroy(srv->options);
g_hash_table_destroy(srv->actions);
g_hash_table_destroy(srv->setups);
}
gboolean plugin_register(server *srv, const gchar *name, PluginInit init) {
plugin *p;

1
src/plugin.h

@ -125,6 +125,7 @@ LI_API gboolean plugin_register(server *srv, const gchar *name, PluginInit init)
/* Internal needed functions */
LI_API void plugin_free(server *srv, plugin *p);
LI_API void server_plugins_free(server *srv);
LI_API gboolean parse_option(server *srv, const char *name, option *opt, option_set *mark);
LI_API void release_option(server *srv, option_set *mark); /**< Does not free the option_set memory */

4
src/plugin_core.c

@ -19,6 +19,7 @@ static action* core_list(server *srv, plugin* p, option *opt) {
if (opt->type == OPTION_ACTION) {
a = opt->value.opt_action.action;
action_acquire(a);
option_free(opt);
return a;
}
@ -148,6 +149,7 @@ static action* core_physical(server *srv, plugin* p, option *opt) {
}
docroot = (GString*) option_extract_value(opt);
option_free(opt);
return action_new_function(core_handle_physical, core_physical_free, docroot);
}
@ -475,7 +477,7 @@ gpointer core_option_server_tag_default(server *srv, plugin *p, gsize ndx) {
UNUSED(p);
UNUSED(ndx);
return g_string_new_len(CONST_STR_LEN("lighttpd-2.0~sandbox"));
return g_string_new_len(CONST_STR_LEN("lighttpd-2.0~sandbox")); /* TODO: fix mem leak */
}
static const plugin_option options[] = {

15
src/server.c

@ -107,6 +107,7 @@ void server_free(server* srv) {
ev_loop_destroy(loop);
}
}
g_array_free(srv->workers, TRUE);
}
{
@ -118,15 +119,13 @@ void server_free(server* srv) {
g_array_free(srv->sockets, TRUE);
}
g_hash_table_destroy(srv->plugins);
g_hash_table_destroy(srv->options);
g_hash_table_destroy(srv->actions);
g_hash_table_destroy(srv->setups);
action_release(srv, srv->mainaction);
g_array_free(srv->plugins_handle_close, TRUE);
server_plugins_free(srv);
g_array_free(srv->plugins_handle_close, TRUE); /* TODO: */
action_release(srv, srv->mainaction);
g_slice_free1(srv->option_count * sizeof(*srv->option_def_values), srv->option_def_values);
if (srv->option_def_values)
g_slice_free1(srv->option_count * sizeof(*srv->option_def_values), srv->option_def_values);
/* free logs */
g_thread_join(srv->log_thread);
@ -211,7 +210,7 @@ static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) {
}
g_atomic_int_inc((gint*) &wrk->connection_load);
TRACE(srv, "selected worker %u with load %u", sel, min_load);
/* TRACE(srv, "selected worker %u with load %u", sel, min_load); */
worker_new_con(srv->main_worker, wrk, &remote_addr, s);
}

2
src/worker.c

@ -233,6 +233,8 @@ void worker_free(worker *wrk) {
g_string_free(wrk->tmp_str, TRUE);
g_string_free(wrk->ts_date_str, TRUE);
g_async_queue_unref(wrk->new_con_queue);
g_slice_free(worker, wrk);
}

Loading…
Cancel
Save