From 82ac450b4b7af7c4370433cf8621c36ff94eece9 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Sat, 16 May 2009 04:03:00 +0200 Subject: [PATCH] Fixed further memory leaks in autotests. --- autotest/test_inf.tcc | 8 ++++---- src/inf.c | 27 +++++++++++++++++---------- src/user.c | 9 ++++++++- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/autotest/test_inf.tcc b/autotest/test_inf.tcc index bc31804..50b87fa 100644 --- a/autotest/test_inf.tcc +++ b/autotest/test_inf.tcc @@ -61,13 +61,13 @@ EXO_TEST(inf_create_setup, }); - +/* FIXME: MEMORY LEAK - Need to fix hub_handle_info_login */ #define CHECK_INF(MSG, EXPECT) \ struct adc_message* msg = adc_msg_parse_verify(inf_user, MSG, strlen(MSG)); \ - int ok = hub_handle_info_login(inf_hub, inf_user, msg); \ + int ok = hub_handle_info_login(inf_hub, inf_user, msg); /* FIXME: MEMORY LEAK */ \ adc_msg_free(msg); \ - if (ok != EXPECT) \ - printf("Expected %d, got %d\n", EXPECT, ok); \ + if (ok == EXPECT) \ + user_set_info(inf_user, 0); \ return ok == EXPECT; diff --git a/src/inf.c b/src/inf.c index 56223ca..592cda0 100644 --- a/src/inf.c +++ b/src/inf.c @@ -686,13 +686,6 @@ static int check_registered_users_only(struct hub_info* hub, struct user* user) return 0; } -#define INF_CHECK(FUNC, HUB, USER, CMD) \ - do { \ - int ret = FUNC(HUB, USER, CMD); \ - if (ret < 0) \ - return ret; \ - } while(0) - static int hub_handle_info_common(struct user* user, struct adc_message* cmd) { /* Remove server restricted flags */ @@ -725,10 +718,15 @@ static int hub_handle_info_low_bandwidth(struct hub_info* hub, struct user* user return 0; } -int hub_handle_info_login(struct hub_info* hub, struct user* user, struct adc_message* cmd) +#define INF_CHECK(FUNC, HUB, USER, CMD) \ + do { \ + int ret = FUNC(HUB, USER, CMD); \ + if (ret < 0) \ + return ret; \ + } while(0) + +int hub_perform_login_checks(struct hub_info* hub, struct user* user, struct adc_message* cmd) { - int need_auth = 0; - /* Make syntax checks. */ INF_CHECK(check_required_login_flags, hub, user, cmd); INF_CHECK(check_cid, hub, user, cmd); @@ -738,6 +736,15 @@ int hub_handle_info_login(struct hub_info* hub, struct user* user, struct adc_me INF_CHECK(check_acl, hub, user, cmd); INF_CHECK(check_logged_in, hub, user, cmd); + return 0; +} + +int hub_handle_info_login(struct hub_info* hub, struct user* user, struct adc_message* cmd) +{ + int need_auth = 0; + + INF_CHECK(hub_perform_login_checks, hub, user, cmd); + /* Private ID must never be broadcasted - drop it! */ adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_PRIVATE_ID); diff --git a/src/user.c b/src/user.c index 3197c04..0897681 100644 --- a/src/user.c +++ b/src/user.c @@ -112,7 +112,14 @@ void user_set_state(struct user* user, enum user_state state) void user_set_info(struct user* user, struct adc_message* cmd) { adc_msg_free(user->info); - user->info = adc_msg_incref(cmd); + if (cmd) + { + user->info = adc_msg_incref(cmd); + } + else + { + user->info = 0; + } }