Fixing memory leak in python support function 76/7176/1
authorczichy <thoralf.czichy@nokia.com>
Thu, 2 Dec 2021 12:15:49 +0000 (14:15 +0200)
committerczichy <thoralf.czichy@nokia.com>
Thu, 2 Dec 2021 12:15:49 +0000 (14:15 +0200)
Issue-ID: RIC-858
Signed-off-by: czichy <thoralf.czichy@nokia.com>
Change-Id: I67eabcf7249baa1b0b191f2ee47be94c1857a58a

src/rmr/common/src/wrapper.c
test/wrapper_static_test.c

index 9d3dd72..63f5d8a 100644 (file)
@@ -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
index 8f7d1ca..6ea25fe 100644 (file)
@@ -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" );