2015-07-30 06:31:59

by Anchit Narang

[permalink] [raw]
Subject: [PATCH] tools/rctest: Fixed memory leak

Removed dynamic allocation of filename and savefile by strdup.
Instead filename and savefile are directly pointing to the argv element.
---
tools/rctest.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/rctest.c b/tools/rctest.c
index bdc1eb5..383d165 100644
--- a/tools/rctest.c
+++ b/tools/rctest.c
@@ -80,8 +80,8 @@ static bdaddr_t auto_bdaddr;
static uint16_t uuid = 0x0000;
static uint8_t channel = 10;

-static char *filename = NULL;
-static char *savefile = NULL;
+static const char *filename = NULL;
+static const char *savefile = NULL;
static int save_fd = -1;

static int master = 0;
@@ -798,11 +798,11 @@ int main(int argc, char *argv[])
break;

case 'B':
- filename = strdup(optarg);
+ filename = optarg;
break;

case 'O':
- savefile = strdup(optarg);
+ savefile = optarg;
break;

case 'N':
--
1.7.9.5



2015-07-30 06:48:38

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] tools/rctest: Fixed memory leak

Hi Anchit,

On Thu, Jul 30, 2015, Anchit Narang wrote:
> Removed dynamic allocation of filename and savefile by strdup.
> Instead filename and savefile are directly pointing to the argv element.
> ---
> tools/rctest.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)

Applied. Thanks.

Johan

2015-07-30 06:15:29

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] tools/rctest: Fixed memory leak

Hi Anchit,

On Thu, Jul 30, 2015, Anchit Narang wrote:
> Removed dynamic allocation of filename and savefile by strdup.
> Instead filename and savefile are directly pointing to the argv element.
> Closed the file before returning from do_send function.
> ---
> tools/rctest.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)

I know I let it slip last time, but in principle independent fixes
should be in separate patches. So please split the fd leak to a separate
patch.

Johan