Fixed further memory leaks in autotests.

This commit is contained in:
Jan Vidar Krey 2009-05-16 04:03:00 +02:00
parent b4f24b21f9
commit 82ac450b4b
3 changed files with 29 additions and 15 deletions

View File

@ -61,13 +61,13 @@ EXO_TEST(inf_create_setup,
}); });
/* FIXME: MEMORY LEAK - Need to fix hub_handle_info_login */
#define CHECK_INF(MSG, EXPECT) \ #define CHECK_INF(MSG, EXPECT) \
struct adc_message* msg = adc_msg_parse_verify(inf_user, MSG, strlen(MSG)); \ 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); \ adc_msg_free(msg); \
if (ok != EXPECT) \ if (ok == EXPECT) \
printf("Expected %d, got %d\n", EXPECT, ok); \ user_set_info(inf_user, 0); \
return ok == EXPECT; return ok == EXPECT;

View File

@ -686,13 +686,6 @@ static int check_registered_users_only(struct hub_info* hub, struct user* user)
return 0; 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) static int hub_handle_info_common(struct user* user, struct adc_message* cmd)
{ {
/* Remove server restricted flags */ /* Remove server restricted flags */
@ -725,10 +718,15 @@ static int hub_handle_info_low_bandwidth(struct hub_info* hub, struct user* user
return 0; 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 need_auth = 0; 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)
{
/* Make syntax checks. */ /* Make syntax checks. */
INF_CHECK(check_required_login_flags, hub, user, cmd); INF_CHECK(check_required_login_flags, hub, user, cmd);
INF_CHECK(check_cid, 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_acl, hub, user, cmd);
INF_CHECK(check_logged_in, 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! */ /* Private ID must never be broadcasted - drop it! */
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_PRIVATE_ID); adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_PRIVATE_ID);

View File

@ -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) void user_set_info(struct user* user, struct adc_message* cmd)
{ {
adc_msg_free(user->info); adc_msg_free(user->info);
user->info = adc_msg_incref(cmd); if (cmd)
{
user->info = adc_msg_incref(cmd);
}
else
{
user->info = 0;
}
} }