Program: 183056
Project: 183056
Buggy source:
/** 
 * Main code for cleaning up a process when it has gone away.  This is called both as a result of the process dying, or directly when stopping  a process when running in single process mode.
 */
private final void cleanUpApplicationRecordLocked(ProcessRecord app,boolean restarting,int index){
  if (index >= 0) {
    mLRUProcesses.remove(index);
  }
  if (app.crashDialog != null) {
    app.crashDialog.dismiss();
    app.crashDialog=null;
  }
  if (app.anrDialog != null) {
    app.anrDialog.dismiss();
    app.anrDialog=null;
  }
  if (app.waitDialog != null) {
    app.waitDialog.dismiss();
    app.waitDialog=null;
  }
  app.crashing=false;
  app.notResponding=false;
  app.resetPackageList();
  app.thread=null;
  app.forcingToForeground=null;
  app.foregroundServices=false;
  killServicesLocked(app,true);
  boolean restart=false;
  int NL=mLaunchingProviders.size();
  if (!app.pubProviders.isEmpty()) {
    Iterator it=app.pubProviders.values().iterator();
    while (it.hasNext()) {
      ContentProviderRecord cpr=(ContentProviderRecord)it.next();
      cpr.provider=null;
      cpr.app=null;
      int i=0;
      if (!app.bad) {
        for (; i < NL; i++) {
          if (mLaunchingProviders.get(i) == cpr) {
            restart=true;
            break;
          }
        }
      }
 else {
        i=NL;
      }
      if (i >= NL) {
        removeDyingProviderLocked(app,cpr);
        NL=mLaunchingProviders.size();
      }
    }
    app.pubProviders.clear();
  }
  for (int i=0; i < NL; i++) {
    ContentProviderRecord cpr=(ContentProviderRecord)mLaunchingProviders.get(i);
    if (cpr.launchingApp == app) {
      if (!app.bad) {
        restart=true;
      }
 else {
        removeDyingProviderLocked(app,cpr);
        NL=mLaunchingProviders.size();
      }
    }
  }
  if (!app.conProviders.isEmpty()) {
    Iterator it=app.conProviders.iterator();
    while (it.hasNext()) {
      ContentProviderRecord cpr=(ContentProviderRecord)it.next();
      cpr.clients.remove(app);
    }
    app.conProviders.clear();
  }
  if (false) {
    for (int i=0; i < NL; i++) {
      ContentProviderRecord cpr=(ContentProviderRecord)mLaunchingProviders.get(i);
      if (cpr.clients.size() <= 0 && cpr.externals <= 0) {
synchronized (cpr) {
          cpr.launchingApp=null;
          cpr.notifyAll();
        }
      }
    }
  }
  skipCurrentReceiverLocked(app);
  if (app.receivers.size() > 0) {
    Iterator<ReceiverList> it=app.receivers.iterator();
    while (it.hasNext()) {
      removeReceiverLocked(it.next());
    }
    app.receivers.clear();
  }
  if (mBackupTarget != null && app.pid == mBackupTarget.app.pid) {
    if (DEBUG_BACKUP)     Log.d(TAG,"String_Node_Str" + mBackupTarget.appInfo + "String_Node_Str");
    try {
      IBackupManager bm=IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
      bm.agentDisconnected(app.info.packageName);
    }
 catch (    RemoteException e) {
    }
  }
  if (restarting) {
    return;
  }
  if (!app.persistent) {
    if (DEBUG_PROCESSES)     Log.v(TAG,"String_Node_Str" + app);
    mProcessNames.remove(app.processName,app.info.uid);
  }
 else   if (!app.removed) {
    app.thread=null;
    app.forcingToForeground=null;
    app.foregroundServices=false;
    if (mPersistentStartingProcesses.indexOf(app) < 0) {
      mPersistentStartingProcesses.add(app);
      restart=true;
    }
  }
  mProcessesOnHold.remove(app);
  if (app == mHomeProcess) {
    mHomeProcess=null;
  }
  if (restart) {
    mProcessNames.put(app.processName,app.info.uid,app);
    startProcessLocked(app,"String_Node_Str",app.processName);
  }
 else   if (app.pid > 0 && app.pid != MY_PID) {
synchronized (mPidsSelfLocked) {
      mPidsSelfLocked.remove(app.pid);
      mHandler.removeMessages(PROC_START_TIMEOUT_MSG,app);
    }
    app.setPid(0);
  }
}

Fixed version (ground truth):
/** 
 * Main code for cleaning up a process when it has gone away.  This is called both as a result of the process dying, or directly when stopping  a process when running in single process mode.
 */
private final void cleanUpApplicationRecordLocked(ProcessRecord app,boolean restarting,int index){
  if (index >= 0) {
    mLRUProcesses.remove(index);
  }
  if (app.crashDialog != null) {
    app.crashDialog.dismiss();
    app.crashDialog=null;
  }
  if (app.anrDialog != null) {
    app.anrDialog.dismiss();
    app.anrDialog=null;
  }
  if (app.waitDialog != null) {
    app.waitDialog.dismiss();
    app.waitDialog=null;
  }
  app.crashing=false;
  app.notResponding=false;
  app.resetPackageList();
  app.thread=null;
  app.forcingToForeground=null;
  app.foregroundServices=false;
  killServicesLocked(app,true);
  boolean restart=false;
  int NL=mLaunchingProviders.size();
  if (!app.pubProviders.isEmpty()) {
    Iterator it=app.pubProviders.values().iterator();
    while (it.hasNext()) {
      ContentProviderRecord cpr=(ContentProviderRecord)it.next();
      cpr.provider=null;
      cpr.app=null;
      int i=0;
      if (!app.bad) {
        for (; i < NL; i++) {
          if (mLaunchingProviders.get(i) == cpr) {
            restart=true;
            break;
          }
        }
      }
 else {
        i=NL;
      }
      if (i >= NL) {
        removeDyingProviderLocked(app,cpr);
        NL=mLaunchingProviders.size();
      }
    }
    app.pubProviders.clear();
  }
  for (int i=0; i < NL; i++) {
    ContentProviderRecord cpr=(ContentProviderRecord)mLaunchingProviders.get(i);
    if (cpr.launchingApp == app) {
      if (!app.bad) {
        restart=true;
      }
 else {
        removeDyingProviderLocked(app,cpr);
        NL=mLaunchingProviders.size();
      }
    }
  }
  if (!app.conProviders.isEmpty()) {
    Iterator it=app.conProviders.keySet().iterator();
    while (it.hasNext()) {
      ContentProviderRecord cpr=(ContentProviderRecord)it.next();
      cpr.clients.remove(app);
    }
    app.conProviders.clear();
  }
  if (false) {
    for (int i=0; i < NL; i++) {
      ContentProviderRecord cpr=(ContentProviderRecord)mLaunchingProviders.get(i);
      if (cpr.clients.size() <= 0 && cpr.externals <= 0) {
synchronized (cpr) {
          cpr.launchingApp=null;
          cpr.notifyAll();
        }
      }
    }
  }
  skipCurrentReceiverLocked(app);
  if (app.receivers.size() > 0) {
    Iterator<ReceiverList> it=app.receivers.iterator();
    while (it.hasNext()) {
      removeReceiverLocked(it.next());
    }
    app.receivers.clear();
  }
  if (mBackupTarget != null && app.pid == mBackupTarget.app.pid) {
    if (DEBUG_BACKUP)     Log.d(TAG,"String_Node_Str" + mBackupTarget.appInfo + "String_Node_Str");
    try {
      IBackupManager bm=IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
      bm.agentDisconnected(app.info.packageName);
    }
 catch (    RemoteException e) {
    }
  }
  if (restarting) {
    return;
  }
  if (!app.persistent) {
    if (DEBUG_PROCESSES)     Log.v(TAG,"String_Node_Str" + app);
    mProcessNames.remove(app.processName,app.info.uid);
  }
 else   if (!app.removed) {
    app.thread=null;
    app.forcingToForeground=null;
    app.foregroundServices=false;
    if (mPersistentStartingProcesses.indexOf(app) < 0) {
      mPersistentStartingProcesses.add(app);
      restart=true;
    }
  }
  mProcessesOnHold.remove(app);
  if (app == mHomeProcess) {
    mHomeProcess=null;
  }
  if (restart) {
    mProcessNames.put(app.processName,app.info.uid,app);
    startProcessLocked(app,"String_Node_Str",app.processName);
  }
 else   if (app.pid > 0 && app.pid != MY_PID) {
synchronized (mPidsSelfLocked) {
      mPidsSelfLocked.remove(app.pid);
      mHandler.removeMessages(PROC_START_TIMEOUT_MSG,app);
    }
    app.setPid(0);
  }
}