From 683e25de59b6b7307a9654b17a4c784e8897d33a Mon Sep 17 00:00:00 2001
From: Jan Willamowius <jan@willamowius.de>
Date: 周日, 21 4月 2019 23:58:07 +0800
Subject: [PATCH] fix memory leaks on error

---
 src/library/pc-identifiers.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/library/pc-identifiers.c b/src/library/pc-identifiers.c
index 7332f4f..2a57eaa 100644
--- a/src/library/pc-identifiers.c
+++ b/src/library/pc-identifiers.c
@@ -281,7 +281,7 @@
 		PcSignature pc_identifier_out) {
 	//TODO base62 encoding, now uses base64
 	PcIdentifier concat_identifiers[2];
-	char* b64_data;
+	char* b64_data = NULL;
 	int b64_size = 0;
 	size_t concatIdentifiersSize = sizeof(PcIdentifier) * 2;
 	//concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize);
@@ -289,6 +289,7 @@
 	memcpy(&concat_identifiers[1], identifier2, sizeof(PcIdentifier));
 	b64_data = base64(concat_identifiers, concatIdentifiersSize, &b64_size);
 	if (b64_size > sizeof(PcSignature)) {
+		free(b64_data);
 		return FUNC_RET_BUFFER_TOO_SMALL;
 	}
 	sprintf(pc_identifier_out, "%.4s-%.4s-%.4s-%.4s", &b64_data[0],
@@ -345,7 +346,7 @@
 		PcIdentifier identifier2_out, PcSignature pc_signature_in) {
 	//TODO base62 encoding, now uses base64
 
-	unsigned char * concat_identifiers;
+	unsigned char * concat_identifiers = NULL;
 	char base64ids[17];
 	int identifiers_size;
 
@@ -353,6 +354,7 @@
 			&base64ids[8], &base64ids[12]);
 	concat_identifiers = unbase64(base64ids, 16, &identifiers_size);
 	if (identifiers_size > sizeof(PcIdentifier) * 2) {
+		free(concat_identifiers);
 		return FUNC_RET_BUFFER_TOO_SMALL;
 	}
 	memcpy(identifier1_out, concat_identifiers, sizeof(PcIdentifier));
@@ -386,6 +388,7 @@
 	for (i = 0; i < 2; i++) {
 		current_strategy_id = strategy_from_pc_id(user_identifiers[i]);
 		if (current_strategy_id == STRATEGY_UNKNOWN) {
+			free(calculated_identifiers);
 			return LICENSE_MALFORMED;
 		}
 		if (current_strategy_id != previous_strategy_id) {

--
Gitblit v1.9.1