Skip to contentSkip to conversation

tools: Fix memory leak

PATCH Applied Andrei Emeltchenko 2 participants 2 messages Sep 16, 2014 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: Fix memory leak

From: Andrei Emeltchenko <[email protected]>

Simplify code and fix memory leaks

---
 tools/btgatt-client.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
tools/btgatt-client.c +5 -6
index f628bbb..41b85ad 100644
@@ -539,8 +539,7 @@ static void cmd_write_value(struct client *cli, char *cmd_str)
 			if (strlen(argv[i]) != 2) {
 				printf("Invalid value byte: %s\n",
 								argv[i]);
-				free(value);
-				return;
+				goto done;
 			}
 
 			value[i-1] = strtol(argv[i], &endptr, 16);
@@ -548,8 +547,7 @@ static void cmd_write_value(struct client *cli, char *cmd_str)
 							|| errno == ERANGE) {
 				printf("Invalid value byte: %s\n",
 								argv[i]);
-				free(value);
-				return;
+				goto done;
 			}
 		}
 	}
@@ -559,11 +557,11 @@ static void cmd_write_value(struct client *cli, char *cmd_str)
 							false, value, length)) {
 			printf("Failed to initiate write without response "
 								"procedure\n");
-			return;
+			goto done;
 		}
 
 		printf("Write command sent\n");
-		return;
+		goto done;
 	}
 
 	if (!bt_gatt_client_write_value(cli->gatt, handle, value, length,
@@ -571,6 +569,7 @@ static void cmd_write_value(struct client *cli, char *cmd_str)
 								NULL, NULL))
 		printf("Failed to initiate write procedure\n");
 
+done:
 	free(value);
 }
 
Signature · 1 line
1.9.1
#1 lore raw

Hi Andrei,

Quoted 4 lines · Andrei Emeltchenko

Simplify code and fix memory leaks

---
 tools/btgatt-client.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Applied. Thanks.

Johan