diff -r 458a8dc68048 -r f21ee22170bf libidav/davqlexec.c --- a/libidav/davqlexec.c Sat Oct 03 18:11:07 2015 +0200 +++ b/libidav/davqlexec.c Sat Oct 03 19:55:43 2015 +0200 @@ -124,7 +124,9 @@ } *error = DAVQL_OK; - return sstrdup_a(a, sstrn(buf->space, buf->size)); + sstr_t ret = sstrdup_a(a, sstrn(buf->space, buf->size)); + ucx_buffer_free(buf); + return ret; } static int fl_add_properties(DavSession *sn, UcxMempool *mp, UcxMap *map, DavQLExpression *expression) { @@ -177,10 +179,11 @@ return create_allprop_propfind_request(); } else if(!sstrcmp(field->name, S("-"))) { ucx_map_free(properties); - return create_basic_propfind_request(); + return create_propfind_request(sn, NULL); } else { if(fl_add_properties(sn, mp, properties, field->expr)) { // TODO: set error + ucx_map_free(properties); return NULL; } } @@ -196,6 +199,7 @@ UcxBuffer *reqbuf = create_propfind_request(sn, list); ucx_list_free(list); + ucx_map_free(properties); return reqbuf; } @@ -271,6 +275,7 @@ if(str.ptr) { UcxKey key = dav_property_key(field->ns, field->name); ucx_map_put(new_properties, key, str.ptr); + free(key.data); } } else { // TODO: error @@ -316,6 +321,7 @@ ucx_mempool_destroy(mp); return result; } + ucx_mempool_reg_destr(mp, rqbuf, (ucx_destructor)ucx_buffer_free); // compile field list UcxList *cfieldlist = NULL; @@ -332,6 +338,7 @@ // TODO: set error string return result; } + ucx_mempool_reg_destr(mp, code, (ucx_destructor)ucx_buffer_free); DavCompiledField *cfield = ucx_mempool_malloc( mp, sizeof(DavCompiledField)); @@ -359,6 +366,7 @@ sstr_t path = dav_format_string(mp->allocator, st->path, ap, &error); if(error) { // TODO: cleanup + ucx_mempool_destroy(mp); return result; } @@ -366,9 +374,11 @@ UcxBuffer *where = dav_compile_expr(sn->context, mp->allocator, st->where, ap); if(st->where && !where) { + // TODO: cleanup ucx_mempool_destroy(mp); return result; } + ucx_mempool_reg_destr(mp, where, (ucx_destructor)ucx_buffer_free); // compile order criterion UcxList *ordercr = NULL; @@ -397,6 +407,7 @@ } else { // error // TODO: cleanup + ucx_mempool_destroy(mp); return result; } } else if(dav_identifier2resprop(column->srctext, &resprop)) { @@ -408,6 +419,7 @@ } else { // error // TODO: cleanup + ucx_mempool_destroy(mp); return result; } @@ -418,6 +430,7 @@ } else { // something is broken // TODO: cleanup + ucx_mempool_destroy(mp); return result; } } @@ -433,6 +446,12 @@ // reuseable response buffer UcxBuffer *rpbuf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND); + if(!rpbuf) { + // TODO: cleanup + ucx_mempool_destroy(mp); + return result; + } + ucx_mempool_reg_destr(mp, rpbuf, (ucx_destructor)ucx_buffer_free); result.result = selroot; result.status = 0; @@ -461,6 +480,7 @@ // error result.status = -1; // TODO: free resources + cleanup_response(&response); break; } @@ -473,6 +493,7 @@ // add properties add_properties(root, &response); + cleanup_response(&response); if(root == selroot) { // The current root is the root of the select query. @@ -500,6 +521,7 @@ sn, &response, root->path); + cleanup_response(&response); // check where clause DavQLStackObj where_result; if(!dav_exec_expr(where, child, &where_result)) { @@ -526,7 +548,7 @@ } } } - + destroy_propfind_parser(parser); } else { dav_session_set_error(sn, ret, http_status); result.result = NULL;