Allocation tracking of pre-tracked buffer returned in a tuple should increment the buffer by 2 (#9408)
* Allocation tracking of pre-tracked buffer returned in a tuple should increment the buffer ref count by 2, not 1. A buffer not pre-tracked has its ref-count set to 2 when it is part of a tuple. A buffer pre-tracked has its value increased by 1, whether it is part of a tuple or not. This is an error. * Adjust range check following review * Fix silly off by 2 error
This commit is contained in:
parent
22586bdf90
commit
6adc38555f
@ -64,8 +64,9 @@ GlobalDataHandle AllocationTracker::RegisterInternal(
|
||||
auto& allocation = FindOrDie(handle_to_allocation_, handle);
|
||||
int ref_count = allocation->ref_count();
|
||||
CHECK_GT(ref_count, 0);
|
||||
VLOG(2) << "ref_count: " << ref_count << " -> " << ref_count + 1;
|
||||
allocation->increment_ref_count();
|
||||
VLOG(2) << "ref_count: " << ref_count << " -> " <<
|
||||
(ref_count + initial_ref_count);
|
||||
allocation->increment_ref_count(initial_ref_count);
|
||||
} else {
|
||||
handle = next_handle_++;
|
||||
VLOG(2) << "ref_count: " << initial_ref_count;
|
||||
|
@ -63,10 +63,10 @@ class Allocation {
|
||||
CHECK_GE(ref_count_, 0);
|
||||
return ref_count_;
|
||||
}
|
||||
void increment_ref_count() {
|
||||
void increment_ref_count(int inc) {
|
||||
CHECK_GT(ref_count_, 0);
|
||||
CHECK_LT(ref_count_, INT_MAX);
|
||||
++ref_count_;
|
||||
CHECK_LE(ref_count_, INT_MAX - inc);
|
||||
ref_count_ += inc;
|
||||
}
|
||||
void decrement_ref_count() {
|
||||
CHECK_GT(ref_count_, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user