Skip to content

Commit f5142c6

Browse files
tsafinclaude
andcommitted
Apply fixes from PR #8: memory leak and dead else branch
Two bugs identified by copilot-swe-agent in PR #8: - lib.rs: fix memory leak on ArrowArrayStreamReader::from_raw() failure. The original code called libc::free() after the ? early-return, so the malloc'd ArrowArrayStream struct leaked if from_raw() failed. Fix: free unconditionally before propagating the error. - lance_writer.cpp: remove dead no-op else branch in StreamState::push(). The else path (queue not full) called not_full_cv_.wait() with a predicate already satisfied, making it a guaranteed immediate return. Removing it clarifies the backpressure logic. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4dbec60 commit f5142c6

2 files changed

Lines changed: 2 additions & 6 deletions

File tree

src/writers/lance_writer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ struct StreamState {
5252
auto waited = std::chrono::duration_cast<std::chrono::nanoseconds>(wait_end - wait_start).count();
5353
stall_ns_.fetch_add(static_cast<uint64_t>(waited), std::memory_order_relaxed);
5454
stall_count_.fetch_add(1, std::memory_order_relaxed);
55-
} else {
56-
not_full_cv_.wait(lock, [&] {
57-
return closed_ || queue_.size() < max_queue_batches_ || !status_.ok();
58-
});
5955
}
6056
if (!status_.ok()) {
6157
return;

third_party/lance-ffi/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ impl LanceWriterHandle {
211211
return Err("Null ArrowArrayStream".to_string());
212212
}
213213

214-
let reader = unsafe { ArrowArrayStreamReader::from_raw(stream_ptr) }
215-
.map_err(|e| format!("Failed to import ArrowArrayStream: {}", e))?;
214+
let result = unsafe { ArrowArrayStreamReader::from_raw(stream_ptr) };
216215
unsafe { libc::free(stream_ptr as *mut c_void) };
216+
let reader = result.map_err(|e| format!("Failed to import ArrowArrayStream: {}", e))?;
217217

218218
let compressed_schema = Arc::new(apply_compression_metadata(reader.schema().as_ref()));
219219
let compression_reader = CompressionReader::new(reader, compressed_schema);

0 commit comments

Comments
 (0)