linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] android/tester-main.c : Fixed Memory leak
@ 2015-06-23  9:24 Anchit Narang
  0 siblings, 0 replies; 6+ messages in thread
From: Anchit Narang @ 2015-06-23  9:24 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: sachin.dev, anupam.r, Anchit Narang

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.
---
 android/tester-main.c |   36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

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 void mgmt_debug(const char *str, void *user_data)
 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 @@ static bool hciemu_post_encr_hook(const void *data, uint16_t len,
 	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 @@ void emu_add_rfcomm_server_action(void)
 	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 bluetooth_disable_action(void)
 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 @@ void bt_set_property_action(void)
 		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_set_property_action(void)
 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 @@ void bt_get_property_action(void)
 		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 @@ void bt_get_device_props_action(void)
 {
 	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 @@ void bt_get_device_props_action(void)
 		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 @@ void bt_get_device_prop_action(void)
 	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 @@ void bt_get_device_prop_action(void)
 		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 @@ void bt_set_device_prop_action(void)
 	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 @@ void bt_set_device_prop_action(void)
 		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 @@ void bt_create_bond_action(void)
 	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 @@ void bt_create_bond_action(void)
 		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 @@ void bt_pin_reply_accept_action(void)
 	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 @@ void bt_pin_reply_accept_action(void)
 		return;
 	}
 
+	step = g_new0(struct step, 1);
+
 	step->action_status = data->if_bluetooth->pin_reply(action_data->addr,
 							TRUE,
 							action_data->pin_len,
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] android/tester-main.c:Fixed Memory leak
@ 2015-07-21 12:14 Anchit Narang
  2015-07-21 12:25 ` Szymon Janc
  0 siblings, 1 reply; 6+ messages in thread
From: Anchit Narang @ 2015-07-21 12:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: sachin.dev, anupam.r

Ping

>------- Original Message -------
>Sender : Anchit Narang<anchit.n@samsung.com> Senior Software Engineer (2)/SRI-Delhi-SWC Group/Samsung Electronics
>Date : Jun 23, 2015 14:54 (GMT+05:30)
>Title : [PATCH] 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.
>---
> android/tester-main.c |   36 +++++++++++++++++++++++++++---------
> 1 file changed, 27 insertions(+), 9 deletions(-)
>
>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 void mgmt_debug(const char *str, void *user_data)
> 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 @@ static bool hciemu_post_encr_hook(const void *data, uint16_t len,
> 	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 @@ void emu_add_rfcomm_server_action(void)
> 	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 bluetooth_disable_action(void)
> 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 @@ void bt_set_property_action(void)
> 		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_set_property_action(void)
> 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 @@ void bt_get_property_action(void)
> 		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 @@ void bt_get_device_props_action(void)
> {
> 	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 @@ void bt_get_device_props_action(void)
> 		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 @@ void bt_get_device_prop_action(void)
> 	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 @@ void bt_get_device_prop_action(void)
> 		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 @@ void bt_set_device_prop_action(void)
> 	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 @@ void bt_set_device_prop_action(void)
> 		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 @@ void bt_create_bond_action(void)
> 	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 @@ void bt_create_bond_action(void)
> 		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 @@ void bt_pin_reply_accept_action(void)
> 	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 @@ void bt_pin_reply_accept_action(void)
> 		return;
> 	}
> 
>+	step = g_new0(struct step, 1);
>+
> 	step->action_status = data->if_bluetooth->pin_reply(action_data->addr,
> 							TRUE,
> 							action_data->pin_len,
>-- 
>1.7.9.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] android/tester-main.c:Fixed Memory leak
  2015-07-21 12:14 Anchit Narang
@ 2015-07-21 12:25 ` Szymon Janc
  0 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2015-07-21 12:25 UTC (permalink / raw)
  To: Anchit Narang; +Cc: linux-bluetooth, sachin.dev, anupam.r

Hi Anchit,

On Tuesday 21 of July 2015 17:44:41 Anchit Narang wrote:
> Ping

I looks like I never got the original patch. Could you resend it?

> >------- Original Message -------
> >Sender : Anchit Narang<anchit.n@samsung.com> Senior Software Engineer
> >(2)/SRI-Delhi-SWC Group/Samsung Electronics Date : Jun 23, 2015 14:54
> >(GMT+05:30)
> >Title : [PATCH] 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.
> >---
> >
> > android/tester-main.c |   36 +++++++++++++++++++++++++++---------
> > 1 file changed, 27 insertions(+), 9 deletions(-)
> >
> >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 void mgmt_debug(const char *str, void
> >*user_data)>
> > 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 @@ static bool hciemu_post_encr_hook(const void *data,
> >uint16_t len,>
> > 	if (len < 4)
> > 	
> > 		return true;
> >
> >+	step = g_new0(struct step, 1);
> >+
> >

I'm not sure if this is like this in original patch or due to citing but make 
sure you don't introduce double new lines in code (same for other places in 
this patch).

> > 	step->callback = ((uint8_t *)data)[3] ? CB_EMU_ENCRYPTION_ENABLED :
> > 						CB_EMU_ENCRYPTION_DISABLED;
> >
> >@@ -2961,13 +2963,15 @@ void emu_add_rfcomm_server_action(void)
> >
> > 	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 bluetooth_disable_action(void)
> >
> > 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 @@ void bt_set_property_action(void)
> >
> > 		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_set_property_action(void)
> >
> > 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 @@ void bt_get_property_action(void)
> >
> > 		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 @@ void bt_get_device_props_action(void)
> >
> > {
> > 
> > 	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 @@ void bt_get_device_props_action(void)
> >
> > 		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 @@ void bt_get_device_prop_action(void)
> >
> > 	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 @@ void bt_get_device_prop_action(void)
> >
> > 		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 @@ void bt_set_device_prop_action(void)
> >
> > 	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 @@ void bt_set_device_prop_action(void)
> >
> > 		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 @@ void bt_create_bond_action(void)
> >
> > 	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 @@ void bt_create_bond_action(void)
> >
> > 		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 @@ void bt_pin_reply_accept_action(void)
> >
> > 	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 @@ void bt_pin_reply_accept_action(void)
> >
> > 		return;
> > 	
> > 	}
> >
> >+	step = g_new0(struct step, 1);
> >+
> >
> > 	step->action_status = data->if_bluetooth->pin_reply(action_data->addr,
> > 	
> > 							TRUE,
> > 							action_data->pin_len,
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth"
> in the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
BR
Szymon Janc

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] android/tester-main.c:Fixed Memory leak
@ 2015-07-22  4:27 Anchit Narang
  2015-07-24 16:46 ` Vinicius Costa Gomes
  2015-07-27  7:21 ` Johan Hedberg
  0 siblings, 2 replies; 6+ messages in thread
From: Anchit Narang @ 2015-07-22  4:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: sachin.dev, anupam.r

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.
---
 android/tester-main.c |   36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

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 void mgmt_debug(const char *str, void *user_data)
 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 @@ static bool hciemu_post_encr_hook(const void *data, uint16_t len,
 	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 @@ void emu_add_rfcomm_server_action(void)
 	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 bluetooth_disable_action(void)
 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 @@ void bt_set_property_action(void)
 		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_set_property_action(void)
 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 @@ void bt_get_property_action(void)
 		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 @@ void bt_get_device_props_action(void)
 {
 	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 @@ void bt_get_device_props_action(void)
 		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 @@ void bt_get_device_prop_action(void)
 	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 @@ void bt_get_device_prop_action(void)
 		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 @@ void bt_set_device_prop_action(void)
 	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 @@ void bt_set_device_prop_action(void)
 		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 @@ void bt_create_bond_action(void)
 	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 @@ void bt_create_bond_action(void)
 		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 @@ void bt_pin_reply_accept_action(void)
 	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 @@ void bt_pin_reply_accept_action(void)
 		return;
 	}
 
+	step = g_new0(struct step, 1);
+
 	step->action_status = data->if_bluetooth->pin_reply(action_data->addr,
 							TRUE,
 							action_data->pin_len,
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] android/tester-main.c:Fixed Memory leak
  2015-07-22  4:27 [PATCH] android/tester-main.c:Fixed Memory leak Anchit Narang
@ 2015-07-24 16:46 ` Vinicius Costa Gomes
  2015-07-27  7:21 ` Johan Hedberg
  1 sibling, 0 replies; 6+ messages in thread
From: Vinicius Costa Gomes @ 2015-07-24 16:46 UTC (permalink / raw)
  To: Anchit Narang, linux-bluetooth; +Cc: sachin.dev, anupam.r

Hi,

Anchit Narang <anchit.n@samsung.com> writes:

> 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.
> ---
>  android/tester-main.c |   36 +++++++++++++++++++++++++++---------
>  1 file changed, 27 insertions(+), 9 deletions(-)
>

Patch looks good.


Cheers,
--
Vinicius

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] android/tester-main.c:Fixed Memory leak
  2015-07-22  4:27 [PATCH] android/tester-main.c:Fixed Memory leak Anchit Narang
  2015-07-24 16:46 ` Vinicius Costa Gomes
@ 2015-07-27  7:21 ` Johan Hedberg
  1 sibling, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2015-07-27  7:21 UTC (permalink / raw)
  To: Anchit Narang; +Cc: linux-bluetooth, sachin.dev, anupam.r

Hi Anchit,

On Wed, Jul 22, 2015, Anchit Narang wrote:
> 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.
> ---
>  android/tester-main.c |   36 +++++++++++++++++++++++++++---------
>  1 file changed, 27 insertions(+), 9 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-07-27  7:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-22  4:27 [PATCH] android/tester-main.c:Fixed Memory leak Anchit Narang
2015-07-24 16:46 ` Vinicius Costa Gomes
2015-07-27  7:21 ` Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2015-07-21 12:14 Anchit Narang
2015-07-21 12:25 ` Szymon Janc
2015-06-23  9:24 [PATCH] android/tester-main.c : Fixed " Anchit Narang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).