android/tester-main.c:Fixed Memory leak
This patch fixes memory leak issues in various functions
by allocating memory to structure step only after intial
checks are performed as control was returning from these
checks without freeing memory allocated to it.
diff --git a/android/tester-main.c b/android/tester-main.c
index 19400fc..3a55792 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -329,7 +329,7 @@
static bool hciemu_post_encr_hook(const void *data, uint16_t len,
void *user_data)
{
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
/*
* Expected data: status (1 octet) + conn. handle (2 octets) +
@@ -338,6 +338,8 @@
if (len < 4)
return true;
+ step = g_new0(struct step, 1);
+
step->callback = ((uint8_t *)data)[3] ? CB_EMU_ENCRYPTION_ENABLED :
CB_EMU_ENCRYPTION_DISABLED;
@@ -2961,13 +2963,15 @@
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *rfcomm_data = current_data_step->set_data;
struct bthost *bthost;
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
if (!rfcomm_data) {
tester_warn("Invalid l2cap_data params");
return;
}
+ step = g_new0(struct step, 1);
+
bthost = hciemu_client_get_host(data->hciemu);
bthost_add_rfcomm_server(bthost, rfcomm_data->channel,
@@ -3010,7 +3014,7 @@
void bt_set_property_action(void)
{
struct test_data *data = tester_get_data();
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
struct step *current_data_step = queue_peek_head(data->steps);
bt_property_t *prop;
@@ -3020,6 +3024,8 @@
return;
}
+ step = g_new0(struct step, 1);
+
prop = (bt_property_t *)current_data_step->set_data;
step->action_status = data->if_bluetooth->set_adapter_property(prop);
@@ -3030,7 +3036,7 @@
void bt_get_property_action(void)
{
struct test_data *data = tester_get_data();
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
struct step *current_data_step = queue_peek_head(data->steps);
bt_property_t *prop;
@@ -3040,6 +3046,8 @@
return;
}
+ step = g_new0(struct step, 1);
+
prop = (bt_property_t *)current_data_step->set_data;
step->action_status = data->if_bluetooth->get_adapter_property(
@@ -3072,7 +3080,7 @@
{
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
if (!current_data_step->set_data) {
tester_debug("bdaddr not defined");
@@ -3080,6 +3088,8 @@
return;
}
+ step = g_new0(struct step, 1);
+
step->action_status =
data->if_bluetooth->get_remote_device_properties(
current_data_step->set_data);
@@ -3092,7 +3102,7 @@
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
if (!action_data) {
tester_warn("No arguments for 'get remote device prop' req.");
@@ -3100,6 +3110,8 @@
return;
}
+ step = g_new0(struct step, 1);
+
step->action_status = data->if_bluetooth->get_remote_device_property(
action_data->addr,
action_data->prop_type);
@@ -3112,7 +3124,7 @@
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
if (!action_data) {
tester_warn("No arguments for 'set remote device prop' req.");
@@ -3120,6 +3132,8 @@
return;
}
+ step = g_new0(struct step, 1);
+
step->action_status = data->if_bluetooth->set_remote_device_property(
action_data->addr,
action_data->prop);
@@ -3132,7 +3146,7 @@
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
if (!action_data || !action_data->addr) {
tester_warn("Bad arguments for 'create bond' req.");
@@ -3140,6 +3154,8 @@
return;
}
+ step = g_new0(struct step, 1);
+
step->action_status =
data->if_bluetooth->create_bond(action_data->addr,
action_data->transport_type ?
@@ -3154,7 +3170,7 @@
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
if (!action_data || !action_data->addr || !action_data->pin) {
tester_warn("Bad arguments for 'pin reply' req.");
@@ -3162,6 +3178,8 @@
return;
}
+ step = g_new0(struct step, 1);
+
step->action_status = data->if_bluetooth->pin_reply(action_data->addr,
TRUE,
action_data->pin_len,