Program: 192925
Project: 192925
Buggy source:
boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator,String operation,boolean secure){
  final WindowSurfaceController surfaceController=winAnimator.mSurfaceController;
  boolean leakedSurface=false;
  boolean killedApps=false;
  EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY,winAnimator.mWin.toString(),winAnimator.mSession.mPid,operation);
  long callingIdentity=Binder.clearCallingIdentity();
  try {
    Slog.i(TAG_WM,"String_Node_Str");
    final int numDisplays=mDisplayContents.size();
    for (int displayNdx=0; displayNdx < numDisplays; ++displayNdx) {
      final WindowList windows=mDisplayContents.valueAt(displayNdx).getWindowList();
      final int numWindows=windows.size();
      for (int winNdx=0; winNdx < numWindows; ++winNdx) {
        final WindowState ws=windows.get(winNdx);
        WindowStateAnimator wsa=ws.mWinAnimator;
        if (wsa.mSurfaceController != null) {
          if (!mSessions.contains(wsa.mSession)) {
            Slog.w(TAG_WM,"String_Node_Str" + ws + "String_Node_Str"+ wsa.mSurfaceController+ "String_Node_Str"+ ws.mToken+ "String_Node_Str"+ ws.mSession.mPid+ "String_Node_Str"+ ws.mSession.mUid);
            wsa.destroySurface();
            ws.setHasSurface(false);
            mForceRemoves.add(ws);
            leakedSurface=true;
          }
 else           if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
            Slog.w(TAG_WM,"String_Node_Str" + ws + "String_Node_Str"+ wsa.mSurfaceController+ "String_Node_Str"+ ws.mAppToken+ "String_Node_Str"+ ws.mAppToken.hasSavedSurface());
            if (SHOW_TRANSACTIONS)             logSurface(ws,"String_Node_Str",null);
            wsa.destroySurface();
            ws.setHasSurface(false);
            leakedSurface=true;
          }
        }
      }
    }
    if (!leakedSurface) {
      Slog.w(TAG_WM,"String_Node_Str");
      SparseIntArray pidCandidates=new SparseIntArray();
      for (int displayNdx=0; displayNdx < numDisplays; ++displayNdx) {
        final WindowList windows=mDisplayContents.valueAt(displayNdx).getWindowList();
        final int numWindows=windows.size();
        for (int winNdx=0; winNdx < numWindows; ++winNdx) {
          final WindowState ws=windows.get(winNdx);
          if (mForceRemoves.contains(ws)) {
            continue;
          }
          WindowStateAnimator wsa=ws.mWinAnimator;
          if (wsa.mSurfaceController != null) {
            pidCandidates.append(wsa.mSession.mPid,wsa.mSession.mPid);
          }
        }
        if (pidCandidates.size() > 0) {
          int[] pids=new int[pidCandidates.size()];
          for (int i=0; i < pids.length; i++) {
            pids[i]=pidCandidates.keyAt(i);
          }
          try {
            if (mActivityManager.killPids(pids,"String_Node_Str",secure)) {
              killedApps=true;
            }
          }
 catch (          RemoteException e) {
          }
        }
      }
    }
    if (leakedSurface || killedApps) {
      Slog.w(TAG_WM,"String_Node_Str");
      if (surfaceController != null) {
        if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC)         logSurface(winAnimator.mWin,"String_Node_Str",null);
        surfaceController.destroyInTransaction();
        winAnimator.mWin.setHasSurface(false);
        scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken);
      }
      try {
        winAnimator.mWin.mClient.dispatchGetNewSurface();
      }
 catch (      RemoteException e) {
      }
    }
  }
  finally {
    Binder.restoreCallingIdentity(callingIdentity);
  }
  return leakedSurface || killedApps;
}

Fixed version (ground truth):
boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator,String operation,boolean secure){
  final WindowSurfaceController surfaceController=winAnimator.mSurfaceController;
  boolean leakedSurface=false;
  boolean killedApps=false;
  EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY,winAnimator.mWin.toString(),winAnimator.mSession.mPid,operation);
  long callingIdentity=Binder.clearCallingIdentity();
  try {
    Slog.i(TAG_WM,"String_Node_Str");
    final int numDisplays=mDisplayContents.size();
    for (int displayNdx=0; displayNdx < numDisplays; ++displayNdx) {
      final WindowList windows=mDisplayContents.valueAt(displayNdx).getWindowList();
      final int numWindows=windows.size();
      for (int winNdx=0; winNdx < numWindows; ++winNdx) {
        final WindowState ws=windows.get(winNdx);
        WindowStateAnimator wsa=ws.mWinAnimator;
        if (wsa.mSurfaceController != null) {
          if (!mSessions.contains(wsa.mSession)) {
            Slog.w(TAG_WM,"String_Node_Str" + ws + "String_Node_Str"+ wsa.mSurfaceController+ "String_Node_Str"+ ws.mToken+ "String_Node_Str"+ ws.mSession.mPid+ "String_Node_Str"+ ws.mSession.mUid);
            wsa.destroySurface();
            ws.setHasSurface(false);
            mForceRemoves.add(ws);
            leakedSurface=true;
          }
 else           if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
            Slog.w(TAG_WM,"String_Node_Str" + ws + "String_Node_Str"+ wsa.mSurfaceController+ "String_Node_Str"+ ws.mAppToken+ "String_Node_Str"+ ws.mAppToken.hasSavedSurface());
            if (SHOW_TRANSACTIONS)             logSurface(ws,"String_Node_Str",false);
            wsa.destroySurface();
            ws.setHasSurface(false);
            leakedSurface=true;
          }
        }
      }
    }
    if (!leakedSurface) {
      Slog.w(TAG_WM,"String_Node_Str");
      SparseIntArray pidCandidates=new SparseIntArray();
      for (int displayNdx=0; displayNdx < numDisplays; ++displayNdx) {
        final WindowList windows=mDisplayContents.valueAt(displayNdx).getWindowList();
        final int numWindows=windows.size();
        for (int winNdx=0; winNdx < numWindows; ++winNdx) {
          final WindowState ws=windows.get(winNdx);
          if (mForceRemoves.contains(ws)) {
            continue;
          }
          WindowStateAnimator wsa=ws.mWinAnimator;
          if (wsa.mSurfaceController != null) {
            pidCandidates.append(wsa.mSession.mPid,wsa.mSession.mPid);
          }
        }
        if (pidCandidates.size() > 0) {
          int[] pids=new int[pidCandidates.size()];
          for (int i=0; i < pids.length; i++) {
            pids[i]=pidCandidates.keyAt(i);
          }
          try {
            if (mActivityManager.killPids(pids,"String_Node_Str",secure)) {
              killedApps=true;
            }
          }
 catch (          RemoteException e) {
          }
        }
      }
    }
    if (leakedSurface || killedApps) {
      Slog.w(TAG_WM,"String_Node_Str");
      if (surfaceController != null) {
        if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC)         logSurface(winAnimator.mWin,"String_Node_Str",false);
        surfaceController.destroyInTransaction();
        winAnimator.mWin.setHasSurface(false);
        scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken);
      }
      try {
        winAnimator.mWin.mClient.dispatchGetNewSurface();
      }
 catch (      RemoteException e) {
      }
    }
  }
  finally {
    Binder.restoreCallingIdentity(callingIdentity);
  }
  return leakedSurface || killedApps;
}