Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 169ef4cc authored by Patrick Scott's avatar Patrick Scott
Browse files

Check for null before returing a chunk from the pool.

Since references can be queued in another thread, the first entry in the pool
could have been queued after processPoolLocked. Check for null and create a new
chunk if the check fails.
parent 208360b2
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -114,15 +114,18 @@ class ByteArrayBuilder {
            length = DEFAULT_CAPACITY;
        }
        synchronized (sPool) {
            // Process any queued references so that sPool does not contain
            // dead entries.
            // Process any queued references and remove them from the pool.
            processPoolLocked();
            if (!sPool.isEmpty()) {
                return sPool.removeFirst().get();
            } else {
                return new Chunk(length);
                Chunk c = sPool.removeFirst().get();
                // The first item may have been queued after processPoolLocked
                // so check for null.
                if (c != null) {
                    return c;
                }
            }
            return new Chunk(length);
        }
    }

    public static class Chunk {