Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tech/v3/resource/stack.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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?*
Expand Down
11 changes: 11 additions & 0 deletions test/tech/v3/resource_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 []))))))))