Help me diagnose inconsistent test failures on unsafe code

I am trying to manually manage memory to implement a custom collection, and I'm running into flaky test failures.

I have a LeafNode class that stores an UnsafeMutablePointer<Int> to store indices of another collection. The important bits look like this:

internal class LeafNode<Key: Comparable> {
    /// The base pointer to the memory storing keys.
    private let keyStorage: UnsafeMutablePointer<Key>

    /// The base pointer to the memory storing indices.
    private let indexStorage: UnsafeMutablePointer<Int>

    /// The number of elements stored in this node.
    private var count: Int
    /// The maximum number of elements in this node.
    private var capacity: Int

    /// Initializes a node with the specified capacity.
    init(capacity: Int) {
        self.keyStorage = .allocate(capacity: capacity)
        self.indexStorage = .allocate(capacity: capacity)
        self.count = 0
        self.capacity = capacity

    deinit {
        keyStorage.deinitialize(count: count)
        indexStorage.deinitialize(count: count)

When inserting key-value pairs into the node, each mutation uses a combination of UnsafeMutablePointer's move() and initalize(to:) methods to ensure that any memory past indexStorage + (count - 1) is uninitialized.

I need a method that increments each index by one. This is what I have:

extension LeafNode {
    func incrementIndices() {
        var indexPointer = indexStorage
        for _ in 0..<count {
            let incremented = indexPointer.move() + 1
            indexPointer.initialize(to: incremented)
            indexPointer = indexPointer.successor()

However when I run a test against this method in a loop or as part of the greater test case, it seems to mutate the keyStorage pointer instead. When the test is run on its own, it succeeds. This is indicative of a problem with my manual memory management, but I'm still new to this and can't quite put my finger on it.

Thanks in advance for any advice!