Program: 41238
Project: 41238
Buggy source:
final void trimApplications(){
synchronized (this) {
    int i;
    for (i=mRemovedProcesses.size() - 1; i >= 0; i--) {
      final ProcessRecord app=mRemovedProcesses.get(i);
      if (app.activities.size() == 0 && app.curReceiver == null && app.services.size() == 0) {
        Slog.i(TAG,"String_Node_Str" + app.processName + "String_Node_Str"+ (app.thread != null ? app.thread.asBinder() : null)+ "String_Node_Str");
        if (app.pid > 0 && app.pid != MY_PID) {
          Process.killProcess(app.pid);
        }
 else {
          try {
            app.thread.scheduleExit();
          }
 catch (          Exception e) {
          }
        }
        cleanUpApplicationRecordLocked(app,false,-1);
        mRemovedProcesses.remove(i);
        if (app.persistent) {
          if (app.persistent) {
            addAppLocked(app.info);
          }
        }
      }
    }
    if (!updateOomAdjLocked()) {
      int numServiceProcs=0;
      for (i=mLruProcesses.size() - 1; i >= 0; i--) {
        final ProcessRecord app=mLruProcesses.get(i);
        if (app.persistent || app.services.size() != 0 || app.curReceiver != null || app.persistentActivities > 0) {
          if (localLOGV)           Slog.v(TAG,"String_Node_Str" + app + "String_Node_Str"+ app.services);
          numServiceProcs++;
        }
      }
      int curMaxProcs=mProcessLimit;
      if (curMaxProcs <= 0)       curMaxProcs=MAX_PROCESSES;
      if (mAlwaysFinishActivities) {
        curMaxProcs=1;
      }
      curMaxProcs+=numServiceProcs;
      for (i=0; i < mLruProcesses.size() && mLruProcesses.size() > curMaxProcs; i++) {
        final ProcessRecord app=mLruProcesses.get(i);
        if (!app.persistent && app.activities.size() == 0 && app.curReceiver == null && app.services.size() == 0) {
          Slog.i(TAG,"String_Node_Str" + app.processName + "String_Node_Str"+ (app.thread != null ? app.thread.asBinder() : null)+ "String_Node_Str");
          if (app.pid > 0 && app.pid != MY_PID) {
            Process.killProcess(app.pid);
          }
 else {
            try {
              app.thread.scheduleExit();
            }
 catch (            Exception e) {
            }
          }
          cleanUpApplicationRecordLocked(app,false,i);
          i--;
        }
      }
      if (Config.LOGV)       Slog.v(TAG,"String_Node_Str" + mLruProcesses.size() + "String_Node_Str"+ curMaxProcs+ "String_Node_Str");
      for (i=0; i < mLruProcesses.size() && mLruProcesses.size() > curMaxProcs; i++) {
        final ProcessRecord app=mLruProcesses.get(i);
        boolean canQuit=!app.persistent && app.curReceiver == null && app.services.size() == 0 && app.persistentActivities == 0;
        int NUMA=app.activities.size();
        int j;
        if (Config.LOGV)         Slog.v(TAG,"String_Node_Str" + app.processName);
        for (j=0; j < NUMA && canQuit; j++) {
          ActivityRecord r=app.activities.get(j);
          if (Config.LOGV)           Slog.v(TAG,"String_Node_Str" + r.intent.getComponent().flattenToShortString() + "String_Node_Str"+ r.haveState+ "String_Node_Str"+ r.visible);
          canQuit=(r.haveState || !r.stateNotNeeded) && !r.visible && r.stopped;
        }
        if (canQuit) {
          for (j=0; j < NUMA; j++) {
            ActivityRecord r=app.activities.get(j);
            if (!r.finishing) {
              r.stack.destroyActivityLocked(r,false);
            }
            r.resultTo=null;
          }
          Slog.i(TAG,"String_Node_Str" + app.processName + "String_Node_Str"+ (app.thread != null ? app.thread.asBinder() : null)+ "String_Node_Str");
          if (app.pid > 0 && app.pid != MY_PID) {
            Process.killProcess(app.pid);
          }
 else {
            try {
              app.thread.scheduleExit();
            }
 catch (            Exception e) {
            }
          }
          cleanUpApplicationRecordLocked(app,false,i);
          i--;
        }
      }
    }
    int curMaxActivities=MAX_ACTIVITIES;
    if (mAlwaysFinishActivities) {
      curMaxActivities=1;
    }
    for (i=0; i < mMainStack.mLRUActivities.size() && mMainStack.mLRUActivities.size() > curMaxActivities; i++) {
      final ActivityRecord r=(ActivityRecord)mMainStack.mLRUActivities.get(i);
      if ((r.haveState || !r.stateNotNeeded) && !r.visible && r.stopped&& !r.persistent&& !r.finishing) {
        final int origSize=mMainStack.mLRUActivities.size();
        r.stack.destroyActivityLocked(r,true);
        if (origSize > mMainStack.mLRUActivities.size()) {
          i--;
        }
      }
    }
  }
}

Fixed version (ground truth):
final void trimApplications(){
synchronized (this) {
    int i;
    for (i=mRemovedProcesses.size() - 1; i >= 0; i--) {
      final ProcessRecord app=mRemovedProcesses.get(i);
      if (app.activities.size() == 0 && app.curReceiver == null && app.services.size() == 0) {
        Slog.i(TAG,"String_Node_Str" + app.processName + "String_Node_Str"+ (app.thread != null ? app.thread.asBinder() : null)+ "String_Node_Str");
        if (app.pid > 0 && app.pid != MY_PID) {
          Process.killProcess(app.pid);
        }
 else {
          try {
            app.thread.scheduleExit();
          }
 catch (          Exception e) {
          }
        }
        cleanUpApplicationRecordLocked(app,false,-1);
        mRemovedProcesses.remove(i);
        if (app.persistent) {
          if (app.persistent) {
            addAppLocked(app.info);
          }
        }
      }
    }
    if (!updateOomAdjLocked()) {
      int numServiceProcs=0;
      for (i=mLruProcesses.size() - 1; i >= 0; i--) {
        final ProcessRecord app=mLruProcesses.get(i);
        if (app.persistent || app.services.size() != 0 || app.curReceiver != null) {
          if (localLOGV)           Slog.v(TAG,"String_Node_Str" + app + "String_Node_Str"+ app.services);
          numServiceProcs++;
        }
      }
      int curMaxProcs=mProcessLimit;
      if (curMaxProcs <= 0)       curMaxProcs=MAX_PROCESSES;
      if (mAlwaysFinishActivities) {
        curMaxProcs=1;
      }
      curMaxProcs+=numServiceProcs;
      for (i=0; i < mLruProcesses.size() && mLruProcesses.size() > curMaxProcs; i++) {
        final ProcessRecord app=mLruProcesses.get(i);
        if (!app.persistent && app.activities.size() == 0 && app.curReceiver == null && app.services.size() == 0) {
          Slog.i(TAG,"String_Node_Str" + app.processName + "String_Node_Str"+ (app.thread != null ? app.thread.asBinder() : null)+ "String_Node_Str");
          if (app.pid > 0 && app.pid != MY_PID) {
            Process.killProcess(app.pid);
          }
 else {
            try {
              app.thread.scheduleExit();
            }
 catch (            Exception e) {
            }
          }
          cleanUpApplicationRecordLocked(app,false,i);
          i--;
        }
      }
      if (Config.LOGV)       Slog.v(TAG,"String_Node_Str" + mLruProcesses.size() + "String_Node_Str"+ curMaxProcs+ "String_Node_Str");
      for (i=0; i < mLruProcesses.size() && mLruProcesses.size() > curMaxProcs; i++) {
        final ProcessRecord app=mLruProcesses.get(i);
        boolean canQuit=!app.persistent && app.curReceiver == null && app.services.size() == 0;
        int NUMA=app.activities.size();
        int j;
        if (Config.LOGV)         Slog.v(TAG,"String_Node_Str" + app.processName);
        for (j=0; j < NUMA && canQuit; j++) {
          ActivityRecord r=app.activities.get(j);
          if (Config.LOGV)           Slog.v(TAG,"String_Node_Str" + r.intent.getComponent().flattenToShortString() + "String_Node_Str"+ r.haveState+ "String_Node_Str"+ r.visible);
          canQuit=(r.haveState || !r.stateNotNeeded) && !r.visible && r.stopped;
        }
        if (canQuit) {
          for (j=0; j < NUMA; j++) {
            ActivityRecord r=app.activities.get(j);
            if (!r.finishing) {
              r.stack.destroyActivityLocked(r,false);
            }
            r.resultTo=null;
          }
          Slog.i(TAG,"String_Node_Str" + app.processName + "String_Node_Str"+ (app.thread != null ? app.thread.asBinder() : null)+ "String_Node_Str");
          if (app.pid > 0 && app.pid != MY_PID) {
            Process.killProcess(app.pid);
          }
 else {
            try {
              app.thread.scheduleExit();
            }
 catch (            Exception e) {
            }
          }
          cleanUpApplicationRecordLocked(app,false,i);
          i--;
        }
      }
    }
    int curMaxActivities=MAX_ACTIVITIES;
    if (mAlwaysFinishActivities) {
      curMaxActivities=1;
    }
    for (i=0; i < mMainStack.mLRUActivities.size() && mMainStack.mLRUActivities.size() > curMaxActivities; i++) {
      final ActivityRecord r=(ActivityRecord)mMainStack.mLRUActivities.get(i);
      if ((r.haveState || !r.stateNotNeeded) && !r.visible && r.stopped&& !r.finishing) {
        final int origSize=mMainStack.mLRUActivities.size();
        r.stack.destroyActivityLocked(r,true);
        if (origSize > mMainStack.mLRUActivities.size()) {
          i--;
        }
      }
    }
  }
}