File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -336,6 +336,14 @@ toC toCMode emitLines mutualGroup (Binder meta root) = renderEmitterState (execS
336336 srcExpr = case lookupMode of
337337 LookupLocal (Capture _) -> " _env->" ++ pathToC path
338338 _ -> pathToC path
339+ -- Refs/pointers don't own their pointee, so the outer
340+ -- env's delete is already a no-op for them. Zeroing
341+ -- the source would also break repeat invocations of
342+ -- the outer closure (second call would see NULL).
343+ isBorrow = case forceTy xobj of
344+ RefTy _ _ -> True
345+ PointerTy _ -> True
346+ _ -> False
339347 in do
340348 appendToSrc
341349 (addIndent indent ++ dstField ++ " = " ++ srcExpr ++ " ;\n " )
@@ -345,13 +353,14 @@ toC toCMode emitLines mutualGroup (Binder meta root) = renderEmitterState (execS
345353 -- delete is a no-op for this field — otherwise both envs
346354 -- would try to free the same heap data on teardown.
347355 case lookupMode of
348- LookupLocal (Capture _) ->
349- appendToSrc
350- ( addIndent indent ++ " memset(&" ++ srcExpr
351- ++ " , 0, sizeof("
352- ++ srcExpr
353- ++ " ));\n "
354- )
356+ LookupLocal (Capture _)
357+ | not isBorrow ->
358+ appendToSrc
359+ ( addIndent indent ++ " memset(&" ++ srcExpr
360+ ++ " , 0, sizeof("
361+ ++ srcExpr
362+ ++ " ));\n "
363+ )
355364 _ -> pure ()
356365 _ -> appendToSrc " "
357366 )
You can’t perform that action at this time.
0 commit comments