From b95822f9efe853a820b01f98e95bdc3f3d4f8044 Mon Sep 17 00:00:00 2001 From: pfelt Date: Sun, 31 May 2009 04:48:01 +0000 Subject: [PATCH] -- fix a couple of memory leaks in store. there is still one in there somewhere reproduceable by sending gobs of "collections /mail" store command consecutively --- src/agents/store/object-model.c | 4 ++++ src/agents/store/query-builder.c | 33 ++++++++++++++++++++++++++++++-- src/agents/store/query-parser.c | 3 +++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/agents/store/object-model.c b/src/agents/store/object-model.c index f46b247..3f5fca1 100644 --- a/src/agents/store/object-model.c +++ b/src/agents/store/object-model.c @@ -757,10 +757,14 @@ StoreObjectIterQueryBuilder(StoreClient *client, QueryBuilder *builder, BOOL sho } + MemFree(sql); QueryBuilderFinish(builder); return 1000; abort: + if (sql) { + MemFree(sql); + } MsgSQLAbortTransaction(client->storedb); QueryBuilderFinish(builder); diff --git a/src/agents/store/query-builder.c b/src/agents/store/query-builder.c index e6ef7d1..d485883 100644 --- a/src/agents/store/query-builder.c +++ b/src/agents/store/query-builder.c @@ -43,11 +43,33 @@ QueryBuilderStart(QueryBuilder *builder) void QueryBuilderFinish(QueryBuilder *builder) { + unsigned int x; + StorePropInfo *newprop; + ExtraLink *link; + QueryBuilder_Param *param; + QueryParserFinish(&builder->internal_parser); QueryParserFinish(&builder->external_parser); + /* free all the properties */ + for(x=0;xproperties);x++) { + newprop = BongoArrayIndex(builder->properties, StorePropInfo *, x); + MemFree(newprop); + } BongoArrayFree(builder->properties, TRUE); + + /* free all the links */ + for(x=0;xlinks);x++) { + link = BongoArrayIndex(builder->links, ExtraLink *, x); + MemFree(link); + } BongoArrayFree(builder->links, TRUE); + + /* free all the parameters */ + for(x=0;xparameters);x++) { + param = BongoArrayIndex(builder->parameters, QueryBuilder_Param *, x); + MemFree(param); + } BongoArrayFree(builder->parameters, TRUE); } @@ -307,6 +329,7 @@ QueryBuilderCreateSQL(QueryBuilder *builder, char **output) { BongoStringBuilder b; unsigned int i; + int ccode; if (BongoStringBuilderInit(&b)) { // unable to start... ick @@ -359,7 +382,8 @@ QueryBuilderCreateSQL(QueryBuilder *builder, char **output) // add in any constraints specified on the various columns if (builder->int_query) { if (QueryExpressionToSQL(builder, builder->internal_parser.start, &b)) { - return -2; + ccode = -2; + goto abort; } } if (builder->int_query && builder->ext_query) { @@ -367,7 +391,8 @@ QueryBuilderCreateSQL(QueryBuilder *builder, char **output) } if (builder->ext_query) { if (QueryExpressionToSQL(builder, builder->external_parser.start, &b)) { - return -3; + ccode = -3; + goto abort; } } @@ -399,6 +424,10 @@ QueryBuilderCreateSQL(QueryBuilder *builder, char **output) BongoStringBuilderDestroy(&b); return 0; + +abort: + BongoStringBuilderDestroy(&b); + return ccode; } static int diff --git a/src/agents/store/query-parser.c b/src/agents/store/query-parser.c index 2d90595..f5962f4 100644 --- a/src/agents/store/query-parser.c +++ b/src/agents/store/query-parser.c @@ -274,6 +274,9 @@ QueryParserFinish(struct parser_state *state) { if (state->start != NULL) { MemFree(state->start); } + if (state->query != NULL) { + MemFree(state->query); + } state->start = state->last = NULL; state->entries = 0; }