diff --git a/src/tech/v3/resource/stack.clj b/src/tech/v3/resource/stack.clj index 862dd35..22f1a54 100644 --- a/src/tech/v3/resource/stack.clj +++ b/src/tech/v3/resource/stack.clj @@ -43,7 +43,7 @@ itself. Else the dispose function is tracked." ([item dispose-fn] (when (and *resource-debug-double-free* - (some #(identical? item %) @*resource-context*)) + (some #(identical? item (first %)) *resource-context*)) (throw (ex-info "Duplicate track detected; this will result in a double free" {:item item}))) (when-not *bound-resource-context?* diff --git a/test/tech/v3/resource_test.clj b/test/tech/v3/resource_test.clj index 8b63002..739bf08 100644 --- a/test/tech/v3/resource_test.clj +++ b/test/tech/v3/resource_test.clj @@ -53,3 +53,14 @@ (is (= #{:gc} (resource/normalize-track-type :auto))) (resource/stack-resource-context (is (= #{:stack} (resource/normalize-track-type :auto))))) + + +(deftest debug-double-free-detects-duplicate-tracks + (binding [stack/*resource-debug-double-free* true] + (stack/with-resource-context + (let [item (Object.)] + (stack/track item (fn [])) + (is (thrown-with-msg? + clojure.lang.ExceptionInfo + #"Duplicate track detected" + (stack/track item (fn []))))))))