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

Commit 0e453d11 authored by Vasu Nori's avatar Vasu Nori
Browse files

requery() should close cursorwindow insead of setting it to null.

just in case GC takes a while to kick in.

Change-Id: I3a00b52afe1303be0c7d6bb561e5c07734e4dcb3
parent faba502a
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -154,7 +154,10 @@ public final class BulkCursorToCursorAdaptor extends AbstractWindowedCursor {
                    false /* the window will be accessed across processes */));
            if (mCount != -1) {
                mPos = -1;
                if (mWindow != null) {
                    mWindow.close();
                    mWindow = null;
                }

                // super.requery() will call onChanged. Do it here instead of relying on the
                // observer from the far side so that observers can see a correct value for mCount
+17 −4
Original line number Diff line number Diff line
@@ -17,12 +17,14 @@
package android.database;

import android.content.res.Resources;
import android.database.sqlite.DatabaseObjectNotClosedException;
import android.database.sqlite.SQLiteClosable;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import android.os.StrictMode;
import android.util.Log;
import android.util.SparseIntArray;

@@ -45,6 +47,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
    private int nWindow;

    private int mStartPos;
    private final Throwable mStackTrace;

    /**
     * Creates a new empty window.
@@ -56,6 +59,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
        int rslt = native_init(sCursorWindowSize, localWindow);
        printDebugMsgIfError(rslt);
        recordNewWindow(Binder.getCallingPid(), nWindow);
        mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
    }

    private void printDebugMsgIfError(int rslt) {
@@ -561,7 +565,16 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {

    @Override
    protected void finalize() {
        // Just in case someone forgot to call close...
        if (nWindow == 0) {
            return;
        }
        if (StrictMode.vmSqliteObjectLeaksEnabled()) {
            StrictMode.onSqliteObjectLeaked(
                    "Releasing cursor in a finalizer. Please ensure " +
                    "that you explicitly call close() on your cursor: ",
                    mStackTrace);
        }
        recordClosingOfWindow(nWindow);
        close_native();
    }
    
@@ -593,6 +606,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
        IBinder nativeBinder = source.readStrongBinder();
        mStartPos = source.readInt();
        int rslt = native_init(nativeBinder);
        mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
        printDebugMsgIfError(rslt);
    }

@@ -607,8 +621,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {

    @Override
    protected void onAllReferencesReleased() {
        int windowId = nWindow;
        recordClosingOfWindow(Binder.getCallingPid(), nWindow);
        recordClosingOfWindow(nWindow);
        close_native();
    }

@@ -623,7 +636,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
        }
    }

    private void recordClosingOfWindow(int pid, int window) {
    private void recordClosingOfWindow(int window) {
        synchronized (sWindowToPidMap) {
            if (sWindowToPidMap.size() == 0) {
                // this means we are not in the ContentProvider.