From b2fc7ef03027d5ff2e56b5790e3e352a838e70d0 Mon Sep 17 00:00:00 2001
From: Jakob Olsson <jakobols@kth.se>
Date: Tue, 15 May 2018 13:31:01 +0200
Subject: [PATCH] small memory leak fix, style change

---
 libmobile.c | 21 ++++-----------------
 libmobile.h | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/libmobile.c b/libmobile.c
index 9354f83..5c0df27 100644
--- a/libmobile.c
+++ b/libmobile.c
@@ -170,10 +170,9 @@ char *lexer(char **input, char *delimiter) {
 
 	if (token)
 		*token = '\0';
-	else {
-		printf("delimiter missing!\n");
+	else
 		return NULL;
-	}
+
 	char *substr = strdup(*input);
 
 	*input = token + strlen(delimiter);
@@ -181,19 +180,6 @@ char *lexer(char **input, char *delimiter) {
 	return substr;
 }
 
-/**
- * Function: parse_apn_profiles
- *
- * Takes a string of APN profile configurations provided by zte-mf823 (which is in an awkward, difficult to read format)
- * and transforms them into a more easily read and worked with JSON format.
- *
- * Parameters:
- * 		apn_profiles - A character string containing the APN profiles.
- *
- * Returns:
- *		The newly generated JSON on success.
- *		NULL on failure.
- */
 struct json_object *parse_apn_profiles(char *apn_profiles)
 {
 	if (strlen(apn_profiles) <= 0) {
@@ -227,7 +213,8 @@ struct json_object *parse_apn_profiles(char *apn_profiles)
 		}
 		char name[1024];
 		sprintf(name, "%d", apn_counter);
-		json_object_object_add(parsed_profiles, name, apn_profile); //be careful here, do we need json_object_get(apn_profile)?
+		json_object_object_add(parsed_profiles, name, json_object_get(apn_profile));
+		json_object_put(apn_profile);
 		apn_counter++;
 	}
 	goto finished;
diff --git a/libmobile.h b/libmobile.h
index a35a929..2d7e50a 100644
--- a/libmobile.h
+++ b/libmobile.h
@@ -40,7 +40,23 @@
  * the caller is then responsible for freeing this memory by calling free(returned_pointer).
  *
  ***************************************************/
+
+/**
+ * __TEMPORARILY PLACED IN THIS HEAD__
+ * Function: parse_apn_profiles
+ *
+ * Takes a string of APN profile configurations provided by zte-mf823 (which is in an awkward, difficult to read format)
+ * and transforms them into a more easily read and worked with JSON format.
+ *
+ * Parameters:
+ * 		apn_profiles - A character string containing the APN profiles.
+ *
+ * Returns:
+ *		The newly generated JSON on success.
+ *		NULL on failure.
+ */
 struct json_object *parse_apn_profiles(char *apn_profiles);
+
 /**
  * Function: mobile_connect_network
  *
-- 
GitLab