Copilot commented on code in PR #51404:
URL: https://github.com/apache/arrow/pull/51404#discussion_r4062894408


##########
python/pyarrow/array.pxi:
##########
@@ -2370,13 +2370,13 @@ cdef class Array(_PandasConvertible):
                 raise BufferError(
                     f"The copy argument is not supported with legacy (pre 1.0) 
DLPack version."
                 )
+            legacy_tensor = GetResultValue(ExportArrayToDLPack(self.sp_array))
             # Note: from March 2025 onwards, it's okay to raise BufferError 
here.
             # Still we keep the V0 version as the V1 was only added in August 
2026.
             warnings.warn(
                 "Exporting an unversioned DLPack capsule is deprecated, "
                 "pass max_version=(1, 0) or higher.",
                 DeprecationWarning, stacklevel=2)

Review Comment:
   The export now runs before `warnings.warn`. If this warning is configured as 
an error (for example with `-W error` or a strict pytest filter), 
`warnings.warn` raises after `ExportArrayToDLPack` has allocated 
`legacy_tensor`, but before the capsule takes ownership of it, leaking the 
exported tensor. Keep the warning before the export, or otherwise release the 
result when warning emission fails.



##########
python/pyarrow/tensor.pxi:
##########
@@ -399,13 +399,13 @@ strides: {self.strides}"""
                 raise BufferError(
                     f"The copy argument is not supported with legacy (pre 1.0) 
DLPack version."
                 )
+            legacy_tensor = 
GetResultValue(ExportTensorToDLPack(self.sp_tensor))
             # Note: from March 2025 onwards, it's okay to raise BufferError 
here.
             # Still we keep the V0 version as the V1 was only added in August 
2026.
             warnings.warn(
                 "Exporting an unversioned DLPack capsule is deprecated, "
                 "pass max_version=(1, 0) or higher.",
                 DeprecationWarning, stacklevel=2)

Review Comment:
   The export now runs before `warnings.warn`. If this warning is configured as 
an error (for example with `-W error` or a strict pytest filter), 
`warnings.warn` raises after `ExportTensorToDLPack` has allocated 
`legacy_tensor`, but before the capsule takes ownership of it, leaking the 
exported tensor. Keep the warning before the export, or otherwise release the 
result when warning emission fails.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to