From 5bdf9fbeb0a6714158535e5aec0619df49b687c6 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Wed, 9 Jun 2021 07:00:20 -0700
Subject: ffi: fix leak on struct/union redefinition.

* ffi.c (make_ffi_type_struct, make_ffi_type_union): When we
are replacing the existing type, if HAVE_FFI is true, we
must free the tft->ft object before clobbering the tft with
zeros.
---
 ffi.c | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'ffi.c')

diff --git a/ffi.c b/ffi.c
index 4c457584..6b67ac4d 100644
--- a/ffi.c
+++ b/ffi.c
@@ -3251,6 +3251,9 @@ static val make_ffi_type_struct(val syntax, val lisp_type,
       free(memb);
       return make_ffi_type_struct(syntax, lisp_type, nil, self);
     }
+#if HAVE_LIBFFI
+    free(tft->ft);
+#endif
     free(tft->memb);
     memset(tft, 0, sizeof *tft);
   }
@@ -3424,6 +3427,9 @@ static val make_ffi_type_union(val syntax, val use_existing, val self)
       free(memb);
       return make_ffi_type_union(syntax, nil, self);
     }
+#if HAVE_LIBFFI
+    free(tft->ft);
+#endif
     free(tft->memb);
     memset(tft, 0, sizeof *tft);
   }
-- 
cgit v1.2.3