Skip to content

Commit 2747421

Browse files
committed
Fix memory leak problems
1 parent 1ab92da commit 2747421

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

protocol.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ change_clt_auth_content(unsigned char *payload, int length,
205205
return 0;
206206
}
207207

208-
tc_log_info(LOG_INFO, 0, "before judge,cont len:%d", length);
209208
for (i = 0; i < 23; i++) {
210209
if (q[i] != 0 ) {
211210
tc_log_info(LOG_WARN, 0, "it is not a login packet");
@@ -225,9 +224,7 @@ change_clt_auth_content(unsigned char *payload, int length,
225224
strcpy(user, str);
226225

227226
pwd = retrieve_user_pwd(user);
228-
if (pwd != NULL) {
229-
tc_log_info(LOG_NOTICE, 0, "user:%s,pwd:%s", user, pwd);
230-
} else {
227+
if (pwd == NULL) {
231228
tc_log_info(LOG_WARN, 0, "user:%s,pwd is null", user);
232229
return 0;
233230
}

tc_mysql_module.c

+42-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ prepare_for_renew_session(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
278278
sec_tcp = NULL;
279279
s->sm.need_rep_greet = 1;
280280

281-
key = get_key(ip->saddr, tcp->source);
281+
key = s->hash_key;
282282

283283
p = (unsigned char *) hash_find(ctx.fir_auth_table, key);
284284

@@ -361,6 +361,46 @@ proc_when_sess_created(tc_sess_t *s)
361361
return TC_OK;
362362
}
363363

364+
static int
365+
proc_when_sess_destroyed(tc_sess_t *s)
366+
{
367+
void *value;
368+
link_list *list;
369+
p_link_node ln, tln;
370+
mysql_table_item_t *item;
371+
372+
value = hash_find(ctx.fir_auth_table, s->hash_key);
373+
if (value != NULL) {
374+
hash_del(ctx.fir_auth_table, ctx.pool, s->hash_key);
375+
tc_log_info(LOG_INFO, 0, "hash del fir auth:%llu", s->hash_key);
376+
}
377+
378+
value = hash_find(ctx.sec_auth_table, s->hash_key);
379+
if (value != NULL) {
380+
hash_del(ctx.sec_auth_table, ctx.pool, s->hash_key);
381+
tc_log_info(LOG_INFO, 0, "hash del for sec auth:%llu", s->hash_key);
382+
}
383+
384+
value = hash_find(ctx.table, s->hash_key);
385+
if (value != NULL) {
386+
item = value;
387+
list = item->list;
388+
ln = link_list_first(list);
389+
while (ln) {
390+
tln = ln;
391+
ln = link_list_get_next(list, ln);
392+
link_list_remove(list, tln);
393+
tc_pfree(ctx.pool, tln->data);
394+
tc_pfree(ctx.pool, tln);
395+
}
396+
397+
tc_pfree(ctx.pool, list);
398+
399+
hash_del(ctx.table, ctx.pool, s->hash_key);
400+
}
401+
402+
return TC_OK;
403+
}
364404

365405
static int
366406
proc_greet(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
@@ -476,7 +516,7 @@ tc_module_t tc_mysql_module = {
476516
prepare_for_renew_session,
477517
check_pack_needed_for_recons,
478518
proc_when_sess_created,
479-
NULL,
519+
proc_when_sess_destroyed,
480520
proc_greet,
481521
proc_auth,
482522
check_needed_for_sec_auth,

0 commit comments

Comments
 (0)