celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject svn commit: r1646498 - /celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
Date Thu, 18 Dec 2014 17:48:14 GMT
Author: bpetri
Date: Thu Dec 18 17:48:13 2014
New Revision: 1646498

URL: http://svn.apache.org/r1646498
Log:
CELIX-190: fixed calculator_proxy leaks

Modified:
    celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c

Modified: celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c?rev=1646498&r1=1646497&r2=1646498&view=diff
==============================================================================
--- celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c (original)
+++ celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c Thu Dec
18 17:48:13 2014
@@ -69,7 +69,7 @@ celix_status_t calculatorProxy_add(calcu
 		root = json_pack("{s:s, s:[ff]}", "m", "add(DD)D", "a", a, b);
 
 		char *data = json_dumps(root, 0);
-		char *reply = malloc(256);
+		char *reply = NULL;
 		int replyStatus = 0;
 
 		calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data,
&reply, &replyStatus);
@@ -80,11 +80,13 @@ celix_status_t calculatorProxy_add(calcu
 			json_t *js_reply = json_loads(reply, 0, &error);
 			if (js_reply) {
 				json_unpack(js_reply, "{s:f}", "r", result);
+				json_decref(js_reply);
 			} else {
 				printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
 				status = CELIX_BUNDLE_EXCEPTION;
 			}
 		}
+		json_decref(root);
 
 		free(data);
 		free(reply);
@@ -103,7 +105,7 @@ celix_status_t calculatorProxy_sub(calcu
 		root = json_pack("{s:s, s:[ff]}", "m", "sub(DD)D", "a", a, b);
 
 		char *data = json_dumps(root, 0);
-		char *reply = malloc(128);
+		char *reply = NULL;
 		int replyStatus = 0;
 
 		calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data,
&reply, &replyStatus);
@@ -113,12 +115,15 @@ celix_status_t calculatorProxy_sub(calcu
 			json_t *js_reply = json_loads(reply, 0, &error);
 			if (js_reply) {
 			    json_unpack(js_reply, "{s:f}", "r", result);
+			    json_decref(js_reply);
 			} else {
 				printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
 				status = CELIX_BUNDLE_EXCEPTION;
 			}
 		}
 
+		json_decref(root);
+
 		free(data);
 		free(reply);
 	} else {
@@ -136,7 +141,7 @@ celix_status_t calculatorProxy_sqrt(calc
 		root = json_pack("{s:s, s:[f]}", "m", "sqrt(D)D", "a", a);
 
 		char *data = json_dumps(root, 0);
-		char *reply = malloc(128);
+		char *reply = NULL;
 		int replyStatus;
 
 		calculator->sendToCallback(calculator->sendToHandler, calculator->endpoint, data,
&reply, &replyStatus);
@@ -146,12 +151,15 @@ celix_status_t calculatorProxy_sqrt(calc
 			json_t *js_reply = json_loads(reply, JSON_DECODE_ANY, &error);
 			if (js_reply) {
 			    json_unpack(js_reply, "{s:f}", "r", result);
+			    json_decref(js_reply);
 			} else {
 				printf("PROXY: got error '%s' for '%s'\n", error.text, reply);
 				status = CELIX_BUNDLE_EXCEPTION;
 			}
 		}
 
+		json_decref(root);
+
 		free(data);
 		free(reply);
 	} else {



Mime
View raw message