From: czichy Date: Thu, 2 Dec 2021 12:15:49 +0000 (+0200) Subject: Fixing memory leak in python support function X-Git-Tag: 4.8.0~1 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=165eaeac93938e2df6eb05273db370ee1c59ab2a;p=ric-plt%2Flib%2Frmr.git Fixing memory leak in python support function Issue-ID: RIC-858 Signed-off-by: czichy Change-Id: I67eabcf7249baa1b0b191f2ee47be94c1857a58a --- diff --git a/src/rmr/common/src/wrapper.c b/src/rmr/common/src/wrapper.c index 9d3dd72..63f5d8a 100644 --- a/src/rmr/common/src/wrapper.c +++ b/src/rmr/common/src/wrapper.c @@ -84,8 +84,16 @@ static int bang_on( char* target, char* src, int max ) { return rc; } +/* + Frees the string that was allocated and returned using rmr_get_consts() +*/ +extern void rmr_free_consts( char* p) { + free(p); +} + /* Returns a set of json with the constants which are set in the header. + Caller must free the returned string using rmr_free_consts() */ extern char* rmr_get_consts( ) { int remain; // bytes remaining in wbuf diff --git a/test/wrapper_static_test.c b/test/wrapper_static_test.c index 8f7d1ca..6ea25fe 100644 --- a/test/wrapper_static_test.c +++ b/test/wrapper_static_test.c @@ -46,7 +46,7 @@ static int wrapper_test( ) { errors += fail_if_true( *b != '{', "first character in buffer not valid json" ); len = strlen( b ) - 1; errors += fail_if_true( *(b+len) != '}', "last character in buffer not valid json" ); - free( b ); + rmr_free_consts( b ); b = build_sval( "foobar", "value", 1 ); errors += fail_if_equal( strlen( b ), 0, "build svalue with sep returned nil buffer" );