Program: 23077
Project: 23077
Buggy source:
/** 
 * Perform any final cleanup before an activity is destroyed.  This can happen either because the activity is finishing (someone called  {@link #finish} on it, or because the system is temporarily destroyingthis instance of the activity to save space.  You can distinguish between these two scenarios with the  {@link #isFinishing} method.<p><em>Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either  {@link #onPause} or{@link #onSaveInstanceState}, not here.</em> This method is usually implemented to free resources like threads that are associated with an activity, so that a destroyed activity does not leave such things around while the rest of its application is still running.  There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away. <p><em>Derived classes must call through to the super class's implementation of this method.  If they do not, an exception will be thrown.</em></p>
 * @see #onPause
 * @see #onStop
 * @see #finish
 * @see #isFinishing
 */
protected void onDestroy(){
  mCalled=true;
  if (mManagedDialogs != null) {
    final int numDialogs=mManagedDialogs.size();
    for (int i=0; i < numDialogs; i++) {
      final ManagedDialog md=mManagedDialogs.valueAt(i);
      if (md.mDialog.isShowing()) {
        md.mDialog.dismiss();
      }
    }
    mManagedDialogs=null;
  }
  int numCursors=mManagedCursors.size();
  for (int i=0; i < numCursors; i++) {
    ManagedCursor c=mManagedCursors.get(i);
    if (c != null) {
      c.mCursor.close();
    }
  }
  mManagedCursors.clear();
}

Fixed version (ground truth):
/** 
 * Perform any final cleanup before an activity is destroyed.  This can happen either because the activity is finishing (someone called  {@link #finish} on it, or because the system is temporarily destroyingthis instance of the activity to save space.  You can distinguish between these two scenarios with the  {@link #isFinishing} method.<p><em>Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either  {@link #onPause} or{@link #onSaveInstanceState}, not here.</em> This method is usually implemented to free resources like threads that are associated with an activity, so that a destroyed activity does not leave such things around while the rest of its application is still running.  There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away. <p><em>Derived classes must call through to the super class's implementation of this method.  If they do not, an exception will be thrown.</em></p>
 * @see #onPause
 * @see #onStop
 * @see #finish
 * @see #isFinishing
 */
protected void onDestroy(){
  mCalled=true;
  if (mManagedDialogs != null) {
    final int numDialogs=mManagedDialogs.size();
    for (int i=0; i < numDialogs; i++) {
      final ManagedDialog md=mManagedDialogs.valueAt(i);
      if (md.mDialog.isShowing()) {
        md.mDialog.dismiss();
      }
    }
    mManagedDialogs=null;
  }
synchronized (mManagedCursors) {
    int numCursors=mManagedCursors.size();
    for (int i=0; i < numCursors; i++) {
      ManagedCursor c=mManagedCursors.get(i);
      if (c != null) {
        c.mCursor.close();
      }
    }
    mManagedCursors.clear();
  }
}