From 9fa5fbbd05d2ade6a6359c16ff6056561fbeca51 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 19 May 2022 09:44:05 -0400 Subject: [PATCH] LP#1974193: fix memory leak in C apps This patch fixes a memory leak that can occur when a C app does the following: - send a non-chunked response - add a response to a bundle to send later - send a request complete status message The leak could add up for long-lived C apps. To test ------- [1] Set a up C app such as Evergreen's open-ils.pcrud and send a lot of requests to it whose responses would not be large enough to be chunked, but not so many as to go over max_requests. It may be helpful to limit the service to just a single child. [2] Check memory usage of the child after the requests are processed. [3] Apply the patch and repeat step 1. This time, memory usage should be less. Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- src/libopensrf/osrf_application.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libopensrf/osrf_application.c b/src/libopensrf/osrf_application.c index b1a149f..b8cb7c1 100644 --- a/src/libopensrf/osrf_application.c +++ b/src/libopensrf/osrf_application.c @@ -765,7 +765,9 @@ static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int osrf_message_set_result( msg, data ); // Serialize the OSRF message into JSON text - char* json = jsonObjectToJSON( osrfMessageToJSON( msg )); + jsonObject* msg_jsonobj = osrfMessageToJSON( msg ); + char* json = jsonObjectToJSON( msg_jsonobj ); + jsonObjectFree( msg_jsonobj ); osrfMessageFree( msg ); // If the new message would overflow the buffer, flush the output buffer first @@ -790,7 +792,9 @@ static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int OSRF_STATUS_COMPLETE ); // Serialize the STATUS message into JSON text - char* json = jsonObjectToJSON( osrfMessageToJSON( status_msg )); + jsonObject* status_msg_jsonobj = osrfMessageToJSON( status_msg ); + char* json = jsonObjectToJSON( status_msg_jsonobj ); + jsonObjectFree( status_msg_jsonobj ); osrfMessageFree( status_msg ); // Add the STATUS message to the output buffer. -- 2.11.0