From 70e45fe529d51421fbeea8828dc1704e3a821d40 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Thu, 22 Jul 2021 13:22:00 +0200 Subject: [PATCH] Use merge-se, not append in ##sys#import to fix memory leak (#1772) Using append on the current module (meta) environment in "import" will extend the environment correctly, but it will grow the list. Instead, we want to replace add those bindings which are new (and possibly replace existing bindings of the same name). This is what merge-se was made for. This potentially slows down performance on import, but should be relatively harmless. --- NEWS | 4 ++++ modules.scm | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index e65f885a..060a9d0e 100644 --- a/NEWS +++ b/NEWS @@ -81,6 +81,10 @@ - Fixed bug in chicken-install regarding variable quotation on UNIX-like systems which prevented installation into paths with spaces (#1685). +- Module system + - Fixed a memory leak when calling (import) multiple times in a row + on the same module (#1772; reported by "plugd" on IRC). + 5.2.0 - Core libraries diff --git a/modules.scm b/modules.scm index 0ba1df49..d91178ff 100644 --- a/modules.scm +++ b/modules.scm @@ -820,8 +820,8 @@ cm (merge-se (module-iexports cm) vsi)) (dm "export-list: " (module-export-list cm))) - (import-env (append vsv (import-env))) - (macro-env (append vss (macro-env))))) + (import-env (merge-se (import-env) vsv)) + (macro-env (merge-se (macro-env) vss)))) (define (module-rename sym prefix) (##sys#string->symbol -- 2.20.1