Skip to content

Commit

Permalink
fix cache memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
haipome committed Jun 11, 2017
1 parent f59edce commit 1bf0063
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions accessws/aw_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static dict_t *backend_cache;
static rpc_clt *listener;
static nw_state *state_context;
static nw_cache *privdata_cache;
static nw_timer cache_timer;

static rpc_clt *matchengine;
static rpc_clt *marketprice;
Expand Down Expand Up @@ -988,6 +989,11 @@ static void cache_dict_val_free(void *val)
free(val);
}

static void on_cache_timer(nw_timer *timer, void *privdata)
{
dict_clear(backend_cache);
}

static int init_backend(void)
{
rpc_clt_type ct;
Expand Down Expand Up @@ -1026,6 +1032,9 @@ static int init_backend(void)
if (backend_cache == NULL)
return -__LINE__;

nw_timer_set(&cache_timer, 60, true, on_cache_timer, NULL);
nw_timer_start(&cache_timer);

return 0;
}

Expand Down
9 changes: 9 additions & 0 deletions marketprice/mp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

static rpc_svr *svr;
static dict_t *dict_cache;
static nw_timer cache_timer;

struct cache_val {
double time;
Expand Down Expand Up @@ -415,6 +416,11 @@ static void cache_dict_val_free(void *val)
free(val);
}

static void on_cache_timer(nw_timer *timer, void *privdata)
{
dict_clear(dict_cache);
}

int init_server(void)
{
rpc_svr_type type;
Expand Down Expand Up @@ -442,6 +448,9 @@ int init_server(void)
if (dict_cache == NULL)
return -__LINE__;

nw_timer_set(&cache_timer, 60, true, on_cache_timer, NULL);
nw_timer_start(&cache_timer);

return 0;
}

9 changes: 9 additions & 0 deletions matchengine/me_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

static rpc_svr *svr;
static dict_t *dict_cache;
static nw_timer cache_timer;

struct cache_val {
double time;
Expand Down Expand Up @@ -1031,6 +1032,11 @@ static void cache_dict_val_free(void *val)
free(val);
}

static void on_cache_timer(nw_timer *timer, void *privdata)
{
dict_clear(dict_cache);
}

int init_server(void)
{
rpc_svr_type type;
Expand Down Expand Up @@ -1058,6 +1064,9 @@ int init_server(void)
if (dict_cache == NULL)
return -__LINE__;

nw_timer_set(&cache_timer, 60, true, on_cache_timer, NULL);
nw_timer_start(&cache_timer);

return 0;
}

0 comments on commit 1bf0063

Please sign in to comment.