From 015e50fd40770fabc0f8a51042d18906af30ae97 Mon Sep 17 00:00:00 2001 From: Eugene Tarassov Date: Tue, 22 May 2012 10:23:59 -0700 Subject: TCF Agent: fixed memory leaks --- agent/tcf/framework/protocol.c | 1 + agent/tcf/services/expressions.c | 1 + server/tcf/services/context-proxy.c | 38 +++++++++++++++++++++++++++---------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/agent/tcf/framework/protocol.c b/agent/tcf/framework/protocol.c index 9574f408..abcb0588 100644 --- a/agent/tcf/framework/protocol.c +++ b/agent/tcf/framework/protocol.c @@ -722,6 +722,7 @@ void protocol_release(Protocol * p) { } } free_services(p); + loc_free(p); } const char * get_agent_id(void) { diff --git a/agent/tcf/services/expressions.c b/agent/tcf/services/expressions.c index 0c386214..fd4d16a8 100644 --- a/agent/tcf/services/expressions.c +++ b/agent/tcf/services/expressions.c @@ -3085,6 +3085,7 @@ static void command_create_cache_client(void * x) { if (err) { write_stringz(&c->out, "null"); + loc_free(e->script); } else { *(e = (Expression *)loc_alloc(sizeof(Expression))) = buf; diff --git a/server/tcf/services/context-proxy.c b/server/tcf/services/context-proxy.c index 942957bf..c76fd7d8 100644 --- a/server/tcf/services/context-proxy.c +++ b/server/tcf/services/context-proxy.c @@ -529,8 +529,9 @@ static void event_context_suspended(Channel * ch, void * args) { send_context_stopped_event(c->ctx); } } - else if (p->rc_done) { - trace(LOG_ALWAYS, "Invalid ID in 'context suspended' event: %s", c->id); + else { + if (p->rc_done) trace(LOG_ALWAYS, "Invalid ID in 'context suspended' event: %s", c->id); + clear_context_suspended_data(c); } } @@ -561,23 +562,40 @@ static void event_context_resumed(Channel * ch, void * args) { } } -static void event_container_suspended(Channel * c, void * args) { +static void event_container_suspended(Channel * ch, void * args) { PeerCache * p = (PeerCache *)args; - ContextCache ctx; + ContextCache buf; + ContextCache * c = &buf; - memset(&ctx, 0, sizeof(ctx)); + assert(p->target == ch); + memset(&buf, 0, sizeof(buf)); write_stringz(&p->host->out, "E"); write_stringz(&p->host->out, RUN_CONTROL); write_stringz(&p->host->out, "containerSuspended"); - json_read_string(p->bck_inp, ctx.id, sizeof(ctx.id)); + json_read_string(p->bck_inp, c->id, sizeof(c->id)); if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX); - ctx.suspend_pc = json_read_uint64(p->bck_inp); + c = find_context_cache(p, c->id); + if (c == NULL) c = &buf; + else clear_context_suspended_data(c); + c->suspend_pc = json_read_uint64(p->bck_inp); if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX); - ctx.suspend_reason = json_read_alloc_string(p->bck_inp); + c->suspend_reason = json_read_alloc_string(p->bck_inp); if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX); - json_read_struct(p->bck_inp, read_context_suspended_data, &ctx); + json_read_struct(p->bck_inp, read_context_suspended_data, c); if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX); - /* TODO: save suspend data in the cache */ + if (c != &buf) { + assert(*EXT(c->ctx) == c); + c->pc_valid = 1; + if (!c->ctx->stopped) { + c->ctx->stopped = 1; + on_context_suspended(c); + send_context_stopped_event(c->ctx); + } + } + else { + if (p->rc_done) trace(LOG_ALWAYS, "Invalid ID in 'container suspended' event: %s", c->id); + clear_context_suspended_data(c); + } json_read_array(p->bck_inp, read_container_suspended_item, p); if (read_stream(p->bck_inp) != 0) exception(ERR_JSON_SYNTAX); if (read_stream(p->bck_inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX); -- cgit v1.2.3