Browse Source

free value always from the calling function

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent
commit
e1504a252f
  1. 8
      src/config_lua.c
  2. 4
      src/config_parser.rl
  3. 6
      src/lighttpd.c
  4. 1
      src/plugin.c
  5. 10
      src/plugin.h
  6. 10
      src/plugin_core.c

8
src/config_lua.c

@ -81,8 +81,10 @@ static int handle_server_action(lua_State *L) {
val = lua_params_to_value(srv, L);
/* TRACE(srv, "%s", "Creating action"); */
a = sa->create_action(srv, sa->p, val);
value_free(val);
if (NULL == (a = sa->create_action(srv, sa->p, val))) {
if (NULL == a) {
lua_pushstring(L, "creating action failed");
lua_error(L);
}
@ -107,13 +109,15 @@ static int handle_server_setup(lua_State *L) {
val = lua_params_to_value(srv, L);
TRACE(srv, "%s", "Calling setup");
/* TRACE(srv, "%s", "Calling setup"); */
if (!ss->setup(srv, ss->p, val)) {
value_free(val);
lua_pushstring(L, "setup failed");
lua_error(L);
}
value_free(val);
return 0;
}

4
src/config_parser.rl

@ -502,6 +502,7 @@
else {
/* normal assignment */
a = option_action(srv, name->data.string->str, val);
value_free(val);
if (a == NULL)
return FALSE;
@ -598,12 +599,15 @@
if (ctx->in_setup_block) {
/* we are in the setup { } block, call setups and don't append to action list */
if (!call_setup(srv, name->data.string->str, val)) {
value_free(val);
return FALSE;
}
value_free(val);
}
else {
al = g_queue_peek_head(ctx->action_list_stack);
a = create_action(srv, name->data.string->str, val);
value_free(val);
if (a == NULL)
return FALSE;

6
src/lighttpd.c

@ -110,12 +110,14 @@ int main(int argc, char *argv[]) {
if (test_config)
return 0;
TRACE(srv, "%s", "Test!");
/* TRACE(srv, "%s", "Test!"); */
server_loop_init(srv);
server_start(srv);
config_parser_finish(srv, ctx_stack, TRUE);
if (!luaconfig)
config_parser_finish(srv, ctx_stack, TRUE);
server_free(srv);
g_free(config_path);

1
src/plugin.c

@ -206,7 +206,6 @@ gboolean parse_option(server *srv, const char *name, value *val, option_set *mar
if (!sopt->parse_option) {
mark->value = value_extract(val);
value_free(val);
} else {
if (!sopt->parse_option(srv, sopt->p, sopt->module_index, val, &mark->value)) {
/* errors should be logged by parse function */

10
src/plugin.h

@ -95,7 +95,8 @@ struct plugin_setup {
struct server_option {
plugin *p;
/** the plugin must free the _content_ of the value (e.g. with option_free)
/** the value is freed with value_free after the parse call, so you
* probably want to extract the content via value_extract*
* val is zero to get the global default value if nothing is specified
* save result in value
*
@ -138,6 +139,7 @@ LI_API gboolean plugin_register(server *srv, const gchar *name, PluginInit init)
LI_API void plugin_free(server *srv, plugin *p);
LI_API void server_plugins_free(server *srv);
/** free val after call (val may be modified by parser) */
LI_API gboolean parse_option(server *srv, const char *name, value *val, option_set *mark);
LI_API void release_option(server *srv, option_set *mark); /**< Does not free the option_set memory */
@ -145,13 +147,13 @@ LI_API void plugins_prepare_callbacks(server *srv);
LI_API void plugins_handle_close(connection *con);
/* Needed for config frontends */
/** For parsing 'somemod.option = "somevalue"' */
/** For parsing 'somemod.option = "somevalue"', free value after call */
LI_API action* option_action(server *srv, const gchar *name, value *value);
/** For parsing 'somemod.action value', e.g. 'rewrite "/url" => "/destination"'
* You need to free the value after it (it should be of type NONE then)
* free value after call
*/
LI_API action* create_action(server *srv, const gchar *name, value *value);
/** For setup function, e.g. 'listen "127.0.0.1:8080"' */
/** For setup function, e.g. 'listen "127.0.0.1:8080"'; free value after call */
LI_API gboolean call_setup(server *srv, const char *name, value *val);
LI_API gboolean plugins_load_default_options(server *srv);

10
src/plugin_core.c

@ -43,7 +43,6 @@ static action* core_list(server *srv, plugin* p, value *val) {
action_acquire(oa->data.val_action.action);
g_array_append_val(a->data.list, oa->data.val_action.action);
}
value_free(val);
return a;
}
@ -89,7 +88,6 @@ static action* core_when(server *srv, plugin* p, value *val) {
action_acquire(val_act->data.val_action.action);
if (act_else) action_acquire(act_else);
a = action_new_condition(val_cond->data.val_cond.cond, val_act->data.val_action.action, act_else);
value_free(val);
return a;
}
@ -117,7 +115,6 @@ static action* core_set(server *srv, plugin* p, value *val) {
return NULL;
}
a = option_action(srv, val_name->data.string->str, val_val);
value_free(val);
return a;
}
@ -152,7 +149,6 @@ static action* core_physical(server *srv, plugin* p, value *val) {
}
docroot = (GString*) value_extract_ptr(val);
value_free(val);
return action_new_function(core_handle_physical, core_physical_free, docroot);
}
@ -350,7 +346,6 @@ static gboolean core_listen(server *srv, plugin* p, value *val) {
}
TRACE(srv, "will listen to '%s'", val->data.string->str);
value_free(val);
return TRUE;
}
@ -415,7 +410,6 @@ static gboolean core_workers(server *srv, plugin* p, value *val) {
ERROR(srv, "workers already called with '%i', overwriting", srv->worker_count);
}
srv->worker_count = workers;
value_free(val);
return TRUE;
}
@ -453,8 +447,6 @@ static gboolean core_option_log_parse(server *srv, plugin *p, size_t ndx, value
}
}
value_free(val);
return TRUE;
}
@ -479,8 +471,6 @@ static gboolean core_option_log_timestamp_parse(server *srv, plugin *p, size_t n
if (!val) return TRUE;
oval->ptr = log_timestamp_new(srv, value_extract(val).string);
value_free(val);
return TRUE;
}

Loading…
Cancel
Save