ocaml: Fix memory leak in bindings for functions that return buffers.
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 29 Nov 2011 17:13:17 +0000 (17:13 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 2 Dec 2011 08:34:00 +0000 (08:34 +0000)
RBufferOut binding didn't free the buffer after copying it onto
the OCaml heap.

Found by valgrind.
(cherry picked from commit 6bd0eec12f2e39360847bfe7a9f50628cc89ed8e)

generator/generator_ocaml.ml

index 4f7548c..10c18e3 100644 (file)
@@ -625,6 +625,7 @@ copy_table (char * const * argv)
        | RBufferOut _ ->
            pr "  rv = caml_alloc_string (size);\n";
            pr "  memcpy (String_val (rv), r, size);\n";
+           pr "  free (r);\n"
       );
 
       pr "  CAMLreturn (rv);\n";