Skip to content

Commit 5778f9b

Browse files
committed
Close #472: don't allow composite schemas to be cached
1 parent de6005f commit 5778f9b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ See also: [compojure-api 1.1.x changelog](./CHANGELOG-1.1.x.md)
66
* Migration instructions: run your program and fix the error messages, which will provide specific instructions.
77
* to circumvent this change, set `-Dcompojure.api.middleware.global-default-formatter=:muuntaja`
88
* stable 2.x will default `:formatter` to `:ring-middleware-format`
9+
* [#472](https://github.com/metosin/compojure-api/issues/472): Fix potential memory leak involving schemas being cached in the multimethod default cache
910

1011
## 2.0.0-alpha33 (2024-04-30)
1112
* Throw an error on malformed `:{body,query,headers}`, in particular if anything other than 2 elements was provided

src/compojure/api/coercion/schema.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
(common/fifo-memoize sc/coercer 1000))
3333

3434
;; don't use coercion for certain types
35-
(defmulti coerce-response? identity :default ::default)
35+
(defmulti coerce-response? #(if (or (class? %)
36+
(keyword? %))
37+
%
38+
::default)
39+
:default ::default)
3640
(defmethod coerce-response? ::default [_] true)
3741
(defmethod coerce-response? File [_] false)
3842

test/compojure/api/coercion/schema_coercion_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,10 @@
285285

286286
(testing "generates valid swagger spec"
287287
(is (validator/validate app)))))
288+
289+
(def some-spec (s/conditional
290+
identity s/Int))
291+
(defmethod cs/coerce-response? some-spec [_] false)
292+
293+
(deftest coerce-response-memory-leak-test
294+
(is (true? (cs/coerce-response? some-spec))))

0 commit comments

Comments
 (0)