Wed, 26 Jun 2013 15:09:54 +0200
fixed some memory leaks
--- a/src/server/config/acl.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/acl.c Wed Jun 26 15:09:54 2013 +0200 @@ -39,24 +39,28 @@ ACLFile *conf = malloc(sizeof(ACLFile)); conf->parser.parse = acl_parse; - conf->file = file; conf->namedACLs = NULL; conf->uriACLs = NULL; conf->pathACLs = NULL; int r = cfg_parse_basic_file((ConfigParser*)conf, in); + UcxMempool *mp = conf->parser.mp; + cfg_list_destr(mp, conf->namedACLs); + cfg_list_destr(mp, conf->uriACLs); + cfg_list_destr(mp, conf->pathACLs); if(r != 0) { free_acl_file(conf); return NULL; } - + fclose(in); return conf; } -void free_acl_file(ACLFile *aclfile) { - +void free_acl_file(ACLFile *conf) { + ucx_mempool_free(conf->parser.mp); + free(conf); } int acl_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) {
--- a/src/server/config/acl.h Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/acl.h Wed Jun 26 15:09:54 2013 +0200 @@ -40,7 +40,6 @@ typedef struct _acl_file { ConfigParser parser; - char *file; UcxList *namedACLs; // ACLConfig list UcxList *uriACLs; // ACLConfig list UcxList *pathACLs; // ACLConfig list
--- a/src/server/config/conf.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/conf.c Wed Jun 26 15:09:54 2013 +0200 @@ -51,7 +51,12 @@ line->line = sstrdup_mp(parser->mp, l); // TODO: check for 0-len str line->object = NULL; line->type = LINE_OTHER; - parser->lines = ucx_dlist_append(parser->lines, line); + if(parser->lines) { + parser->lines = ucx_dlist_append(parser->lines, line); + } else { + parser->lines = ucx_dlist_append(parser->lines, line); + cfg_dlist_destr(parser->mp, parser->lines); + } // check if the line contains something l = cfg_trim_comment(l); @@ -107,6 +112,7 @@ } if(r != 0) { + free(org_ptr); return -1; } } @@ -353,8 +359,9 @@ } // add param to list - plist = ucx_list_append(plist, param); // TODO: use mp + plist = ucx_list_append(plist, param); } + cfg_list_destr(mp, plist); return plist; } @@ -525,7 +532,12 @@ } // add param to list - tag->param = ucx_list_append(tag->param, param); + if(tag->param) { + tag->param = ucx_list_append(tag->param, param); + } else { + tag->param = ucx_list_append(tag->param, param); + cfg_list_destr(mp, tag->param); + } } return tag; @@ -582,3 +594,51 @@ } */ +static void cfg_list_free(void *list) { + ucx_list_free(list); +} +static void cfg_dlist_free(void *dlist) { + ucx_dlist_free(dlist); +} +static void cfg_map_free(void *map) { + ucx_map_free(map); +} + +void cfg_list_destr(UcxMempool *mp, UcxList *list) { + if(list) { + ucx_mempool_reg_destr(mp, list, cfg_list_free); + } +} + +void cfg_dlist_destr(UcxMempool *mp, UcxDlist *dlist) { + if(dlist) { + ucx_mempool_reg_destr(mp, dlist, cfg_dlist_free); + } +} + +void cfg_map_destr(UcxMempool *mp, UcxMap *map) { + if(map) { + ucx_mempool_reg_destr(mp, map, cfg_map_free); + } +} + +UcxList* cfg_list_append(UcxMempool *mp, UcxList *list, void *data) { + if(list) { + return ucx_list_append(list, data); + } else { + UcxList *r = ucx_list_append(list, data); + cfg_list_destr(mp, r); + return r; + } +} + +UcxDlist* cfg_dlist_append(UcxMempool *mp, UcxDlist *list, void *data) { + if(list) { + return ucx_dlist_append(list, data); + } else { + UcxDlist *r = ucx_dlist_append(list, data); + cfg_dlist_destr(mp, r); + return r; + } +} +
--- a/src/server/config/conf.h Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/conf.h Wed Jun 26 15:09:54 2013 +0200 @@ -138,6 +138,12 @@ sstr_t cfg_directive_pstr1(ConfigDirective *dir); +void cfg_list_destr(UcxMempool *mp, UcxList *list); +void cfg_dlist_destr(UcxMempool *mp, UcxDlist *list); +void cfg_map_destr(UcxMempool *mp, UcxMap *map); +UcxList* cfg_list_append(UcxMempool *mp, UcxList *list, void *data); +UcxDlist* cfg_dlist_append(UcxMempool *mp, UcxDlist *list, void *data); + #ifdef __cplusplus } #endif
--- a/src/server/config/initconf.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/initconf.c Wed Jun 26 15:09:54 2013 +0200 @@ -44,6 +44,7 @@ conf->directives = NULL; int r = cfg_parse_basic_file((ConfigParser*)conf, in); + cfg_dlist_destr(conf->parser.mp, conf->directives); if(r != 0) { // TODO: free return NULL; @@ -55,12 +56,6 @@ } void free_init_config(InitConfig *conf) { - if(conf->directives != NULL) { - ucx_dlist_free(conf->directives); - } - if(conf->parser.lines != NULL) { - ucx_dlist_free(conf->parser.lines); - } ucx_mempool_free(conf->parser.mp); free(conf); }
--- a/src/server/config/keyfile.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/keyfile.c Wed Jun 26 15:09:54 2013 +0200 @@ -43,6 +43,7 @@ conf->users = NULL; int r = cfg_parse_basic_file((ConfigParser*)conf, in); + cfg_list_destr(conf->parser.mp, conf->users); if(r != 0) { // TODO: free return NULL;
--- a/src/server/config/mimeconf.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/mimeconf.c Wed Jun 26 15:09:54 2013 +0200 @@ -32,6 +32,11 @@ #include "mimeconf.h" +typedef struct { + ucx_destructor destructor; + void *ptr; +} ucx_regdestr; + MimeConfig *load_mime_config(char *file) { FILE *in = fopen(file, "r"); if(in == NULL) { @@ -43,8 +48,8 @@ conf->file = file; conf->directives = NULL; conf->ntypes = 0; - int r = cfg_parse_basic_file((ConfigParser*)conf, in); + cfg_list_destr(conf->parser.mp, conf->directives); if(r != 0) { // TODO: free return NULL; @@ -56,12 +61,6 @@ } void free_mime_config(MimeConfig *conf) { - if(conf->directives != NULL) { - ucx_list_free(conf->directives); - } - if(conf->parser.lines != NULL) { - ucx_dlist_free(conf->parser.lines); - } ucx_mempool_free(conf->parser.mp); free(conf); } @@ -85,13 +84,15 @@ size_t nx = 0; sstr_t *exts = sstrsplit(param->value, sstrn(",", 1), &nx); for(int i=0;i<nx;i++) { - dir->exts = ucx_list_append(dir->exts, exts[i].ptr); + sstr_t extstr = sstrdup_mp(mp, exts[i]); + dir->exts = ucx_list_append(dir->exts, extstr.ptr); + free(exts[i].ptr); } - free(exts); } } + cfg_list_destr(mp, dir->exts); conf->directives = ucx_list_append(conf->directives, dir); conf->ntypes++;
--- a/src/server/config/objconf.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/objconf.c Wed Jun 26 15:09:54 2013 +0200 @@ -50,7 +50,7 @@ conf->conditions = NULL; conf->levels = NULL; conf->objects = NULL; - conf->lines = NULL; + //conf->lines = NULL; int r = cfg_parse_basic_file((ConfigParser*)conf, in); if(r != 0) { @@ -64,33 +64,10 @@ } void free_object_config(ObjectConfig *conf) { - // free all objects - UcxDlist *objects = conf->objects; - while(objects != NULL) { - ConfigObject *obj = objects->data; - // free all directive lists - for(int i=0;i<6;i++) { - if(obj->directives[i]) { - ucx_dlist_free(obj->directives[i]); - } - } - - objects = objects->next; - } - if(conf->objects) { - ucx_dlist_free(conf->objects); - } - // free other lists if(conf->levels) { ucx_list_free(conf->levels); } - if(conf->lines) { - ucx_dlist_free(conf->lines); - } - if(conf->conditions) { - ucx_dlist_free(conf->conditions); - } // free mempool ucx_mempool_free(conf->parser.mp); @@ -145,6 +122,7 @@ } int objconf_on_begin_tag(ObjectConfig *conf, ConfigTag *tag) { + UcxMempool *mp = conf->parser.mp; if(tag->type_num != TAG_OBJECT) { ConfigParserLevel *l = conf->levels->data; if(l->tag->type_num != TAG_OBJECT) { @@ -163,7 +141,7 @@ obj->ppath = cfg_param_get(tag->param, sstr("ppath")); conf->obj = obj; - conf->objects = ucx_dlist_append(conf->objects, obj); + conf->objects = cfg_dlist_append(mp, conf->objects, obj); // create tree level object ConfigParserLevel *lvl = OBJ_NEW(conf->parser.mp, ConfigParserLevel); @@ -251,7 +229,8 @@ } // add directive to current object - conf->obj->directives[dir->type_num] = ucx_dlist_append( + conf->obj->directives[dir->type_num] = cfg_dlist_append( + conf->parser.mp, conf->obj->directives[dir->type_num], dir);
--- a/src/server/config/objconf.h Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/objconf.h Wed Jun 26 15:09:54 2013 +0200 @@ -57,7 +57,7 @@ typedef struct _obj_conf { ConfigParser parser; char *file; - UcxDlist *lines; + //UcxDlist *lines; UcxDlist *conditions; UcxDlist *objects;
--- a/src/server/config/serverconf.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/config/serverconf.c Wed Jun 26 15:09:54 2013 +0200 @@ -41,11 +41,11 @@ ServerConfig *conf = malloc(sizeof(ServerConfig)); conf->parser.parse = serverconf_parse; conf->file = file; - conf->objects = ucx_map_new(161); - + conf->objects = ucx_map_new(16); conf->obj = NULL; int r = cfg_parse_basic_file((ConfigParser*)conf, in); + cfg_map_destr(conf->parser.mp, conf->objects); if(r != 0) { // TODO: free return NULL; @@ -57,11 +57,13 @@ } void free_server_config(ServerConfig *conf) { - // TODO + ucx_mempool_free(conf->parser.mp); + free(conf); } int serverconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line){ ServerConfig *conf = p; + UcxMempool *mp = conf->parser.mp; begin->type = cfg_get_line_type(line); switch(begin->type) { @@ -79,7 +81,7 @@ // add object to server config UcxList *list = ucx_map_sstr_get(conf->objects, obj->type); - list = ucx_list_append(list, obj); + list = cfg_list_append(mp, list, obj); ucx_map_sstr_put(conf->objects, obj->type, list); conf->obj = obj; @@ -107,7 +109,7 @@ d->end = end; //printf("%s.%s\n", conf->obj->type.ptr, d->directive_type.ptr); - conf->obj->directives = ucx_dlist_append(conf->obj->directives, d); + conf->obj->directives = cfg_dlist_append(mp, conf->obj->directives, d); } } return 0;
--- a/src/server/daemon/auth.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/auth.c Wed Jun 26 15:09:54 2013 +0200 @@ -137,7 +137,7 @@ cusr->authdb = strdup(authdb); cusr->password = strdup(password); - cusr->groups = calloc(numgroups, sizeof(sstr_t)); + cusr->groups = numgroups ? calloc(numgroups, sizeof(sstr_t)) : NULL; cusr->numgroups = numgroups; for(int i=0;i<numgroups;i++) { cusr->groups[i] = sstrdup(sstr(groups[i]));
--- a/src/server/daemon/config.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/config.c Wed Jun 26 15:09:54 2013 +0200 @@ -93,8 +93,8 @@ char *func_name = pblock_findval("fn", d->param); d->func = get_function(func_name); if(d->func == NULL) { + pblock_free(d->param); free(d); - pblock_free(d->param); //dirs = dirs->next; log_ereport( LOG_MISCONFIG, @@ -110,9 +110,13 @@ LOG_FAILURE, "Error running Init function %s", func_name); + pblock_free(d->param); + free(d); return 1; } - + + pblock_free(d->param); + free(d); dirs = dirs->next; } @@ -150,6 +154,10 @@ * VirtualServer (dependencies: Listener) */ + /* + * free stuff on error + */ + // init logfile first UcxList *lfl = ucx_map_sstr_get(serverconf->objects, sstrn("LogFile", 7)); if(lfl != NULL) { @@ -257,7 +265,8 @@ ls = ls->next; } - + + free_server_config(serverconf); return serverconfig; } @@ -790,6 +799,7 @@ mime_conf_unref(old_conf); } + free_mime_config(mimecfg); return 0; }
--- a/src/server/daemon/event_bsd.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/event_bsd.c Wed Jun 26 15:09:54 2013 +0200 @@ -69,10 +69,7 @@ conf->handler = ev; conf->port = ev->ports[i]; - ev_thr_conf_t *thrconf = malloc(sizeof(ev_thr_conf_t)); - thrconf->handler = ev; - thrconf->port = ev->ports[i]; - systhread_start(0, 0, (thrstartfunc)ev_handle_events, thrconf); + systhread_start(0, 0, (thrstartfunc)ev_handle_events, conf); /* TODO: error handling */ }
--- a/src/server/daemon/event_linux.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/event_linux.c Wed Jun 26 15:09:54 2013 +0200 @@ -76,10 +76,7 @@ conf->handler = ev; conf->ep = ev->ep[i]; - ev_thr_conf_t *thrconf = malloc(sizeof(ev_thr_conf_t)); - thrconf->handler = ev; - thrconf->ep= ev->ep[i]; - systhread_start(0, 0, (thrstartfunc)ev_handle_events, thrconf); + systhread_start(0, 0, (thrstartfunc)ev_handle_events, conf); /* TODO: error handling */ }
--- a/src/server/daemon/event_solaris.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/event_solaris.c Wed Jun 26 15:09:54 2013 +0200 @@ -69,11 +69,8 @@ conf->handler = ev; conf->port = ev->ports[i]; - ev_thr_conf_t *thrconf = malloc(sizeof(ev_thr_conf_t)); - thrconf->handler = ev; - thrconf->port = ev->ports[i]; - systhread_start(0, 0, (thrstartfunc)ev_handle_events, thrconf); - /* TODO: error handling */ + systhread_start(0, 0, (thrstartfunc)ev_handle_events, conf); + // TODO: error handling } return ev; @@ -91,11 +88,11 @@ timeout.tv_sec = 600; for(;;) { - /* wait for events */ + // wait for events uint_t nev = 1; int ret = port_getn(port, events, 16, &nev, &timeout); if(ret == -1) { - /* TODO: check for error */ + // TODO: check for error perror("port_getn"); continue; } @@ -120,7 +117,7 @@ } } -/* returns a event handler port */ +// returns a event handler port int ev_get_port(event_handler_t *h) { int nps = h->nports; if(nps == 1) {
--- a/src/server/daemon/httprequest.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/httprequest.c Wed Jun 26 15:09:54 2013 +0200 @@ -403,7 +403,7 @@ /* * keep the connection object * the sn->config is referenced by the connection, so we don't - * unref the configuration + * unref it */ } else { close(sn->connection->fd);
--- a/src/server/daemon/log.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/log.c Wed Jun 26 15:09:54 2013 +0200 @@ -237,6 +237,7 @@ /* cleanup */ free(lmsg.ptr); + free(lpre.ptr); free(message.ptr); return 0;
--- a/src/server/daemon/main.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/main.c Wed Jun 26 15:09:54 2013 +0200 @@ -97,7 +97,7 @@ //test(); /* if the -c parameter is specified, we don't create a daemon */ - int d = 1; + int d = 0; for(int i=0;i<argc;i++) { char *p = argv[i]; if(p[0] == '-' && p[1] == 'c') {
--- a/src/server/daemon/sessionhandler.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/daemon/sessionhandler.c Wed Jun 26 15:09:54 2013 +0200 @@ -37,6 +37,7 @@ #include "httpparser.h" #include "log.h" #include "error.h" +#include "httplistener.h" typedef struct _event_http_io { HTTPRequest *request; @@ -185,7 +186,7 @@ } } -int evt_request_input(event_handler_t *handler, event_t *event) { +int evt_request_input(event_handler_t *handler, event_t *event) { EventHttpIO *io = event->cookie; HttpParser *parser = io->parser; HTTPRequest *request = io->request; @@ -241,7 +242,7 @@ return 0; } -int evt_request_finish(event_handler_t *h, event_t *event) { +int evt_request_finish(event_handler_t *h, event_t *event) { EventHttpIO *io = event->cookie; HttpParser *parser = io->parser; HTTPRequest *request = io->request; @@ -275,6 +276,7 @@ HTTPRequest *request = io->request; close(request->connection->fd); + cfg_unref(request->connection->listener->cfg); header_array_free(request->headers); free(request);
--- a/src/server/webdav/webdav.c Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/webdav/webdav.c Wed Jun 26 15:09:54 2013 +0200 @@ -540,8 +540,8 @@ /* WebDAV Default Backend */ static PersistenceManager dav_file_backend = { - NULL, - NULL, + dav_rq_propfind_begin, + dav_rq_propfind_end, dav_rq_propfind, dav_rq_proppatch, 0 @@ -551,6 +551,14 @@ return &dav_file_backend; } +void dav_rq_propfind_begin(PersistenceManager *mgr, PropfindRequest *rq) { + +} + +void dav_rq_propfind_end(PersistenceManager *mgr, PropfindRequest *rq) { + +} + void dav_rq_propfind(PersistenceManager *b, PropfindRequest *rq ,char *path) { struct stat st; if(stat(path, &st) != 0) { @@ -633,8 +641,8 @@ /* XmlNsMap */ XmlNsMap* xmlnsmap_create(pool_handle_t *pool) { - XmlNsMap *map = malloc(sizeof(XmlNsMap)); - UcxMap *uxm = ucx_map_new(16); + XmlNsMap *map = pool_malloc(pool, sizeof(XmlNsMap)); + UcxMap *uxm = ucx_map_new(16); // TODO: use pool for map if(map == NULL || uxm == NULL) { return NULL; } @@ -677,7 +685,7 @@ xmlns->prefix = pool_calloc(map->pool, 1, 8); xmlns->prelen = snprintf(xmlns->prefix, 7, "x%d", map->num); - ucx_map_cstr_put(map->map, ns, xmlns); /* TODO: check return value */ + ucx_map_cstr_put(map->map, ns, xmlns); // TODO: check return value map->num++; return xmlns; }
--- a/src/server/webdav/webdav.h Tue Jun 25 22:18:59 2013 +0200 +++ b/src/server/webdav/webdav.h Wed Jun 26 15:09:54 2013 +0200 @@ -50,8 +50,10 @@ PersistenceManager* create_property_backend(); -void dav_rq_propfind(PersistenceManager *b, PropfindRequest *rq, char *path); -void dav_rq_proppatch(PersistenceManager *b, ProppatchRequest *rq); +void dav_rq_propfind_begin(PersistenceManager *mgr, PropfindRequest *rq); +void dav_rq_propfind_end(PersistenceManager *mgr, PropfindRequest *rq); +void dav_rq_propfind(PersistenceManager *mgr, PropfindRequest *rq, char *path); +void dav_rq_proppatch(PersistenceManager *mgr, ProppatchRequest *rq); #ifdef __cplusplus