From 166a7387cb3a83b24dd4b9279877338c758eb8b6 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 12 Nov 2019 14:00:35 -0500 Subject: Fix ref counting bug in cpu-hello-world (#1119) * Fix ref counting bug in cpu-hello-world that meant session was not released correctly. * Fix typo. --- examples/cpu-hello-world/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'examples/cpu-hello-world/main.cpp') diff --git a/examples/cpu-hello-world/main.cpp b/examples/cpu-hello-world/main.cpp index 4ece04da2..6e06f64bc 100644 --- a/examples/cpu-hello-world/main.cpp +++ b/examples/cpu-hello-world/main.cpp @@ -49,7 +49,10 @@ static SlangResult _innerMain(int argc, char** argv) // somewhat heavy-weight operation. When possible, an application // should try to re-use the same session across multiple compiles. // - ComPtr slangSession(spCreateSession(NULL)); + // NOTE that we use attach instead of setting via assignment, as assignment will increase + // the refcount. spCreateSession returns a IGlobalSession with a refcount of 1. + ComPtr slangSession; + slangSession.attach(spCreateSession(NULL)); // As touched on earlier, in order to generate the final executable code, // the slang code is converted into C++, and that C++ needs a 'prelude' which -- cgit v1.2.3