Program: 42046
Project: 42046
Buggy source:
Surface createSurfaceLocked(){
  if (mSurface == null) {
    mReportDestroySurface=false;
    mSurfacePendingDestroy=false;
    mDrawPending=true;
    mCommitDrawPending=false;
    mReadyToShow=false;
    if (mAppToken != null) {
      mAppToken.allDrawn=false;
    }
    int flags=0;
    if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
      flags|=Surface.PUSH_BUFFERS;
    }
    if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SECURE) != 0) {
      flags|=Surface.SECURE;
    }
    if (DEBUG_VISIBILITY)     Slog.v(TAG,"String_Node_Str" + mSession.mSurfaceSession + "String_Node_Str"+ this+ "String_Node_Str"+ mFrame.width()+ "String_Node_Str"+ mFrame.height()+ "String_Node_Str"+ mAttrs.format+ "String_Node_Str"+ flags);
    int w=mFrame.width();
    int h=mFrame.height();
    if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
      w=mRequestedWidth;
      h=mRequestedHeight;
    }
    if (w <= 0)     w=1;
    if (h <= 0)     h=1;
    try {
      mSurface=new Surface(mSession.mSurfaceSession,mSession.mPid,mAttrs.getTitle().toString(),0,w,h,mAttrs.format,flags);
      if (SHOW_TRANSACTIONS)       Slog.i(TAG,"String_Node_Str" + mSurface + "String_Node_Str"+ mSession.mSurfaceSession+ "String_Node_Str"+ mSession.mPid+ "String_Node_Str"+ mAttrs.format+ "String_Node_Str"+ Integer.toHexString(flags)+ "String_Node_Str"+ this);
    }
 catch (    Surface.OutOfResourcesException e) {
      Slog.w(TAG,"String_Node_Str");
      reclaimSomeSurfaceMemoryLocked(this,"String_Node_Str");
      return null;
    }
catch (    Exception e) {
      Slog.e(TAG,"String_Node_Str",e);
      return null;
    }
    if (localLOGV)     Slog.v(TAG,"String_Node_Str" + mSurface + "String_Node_Str"+ mFrame.left+ "String_Node_Str"+ mFrame.top+ "String_Node_Str"+ mAnimLayer);
    if (SHOW_TRANSACTIONS) {
      Slog.i(TAG,"String_Node_Str");
      if (SHOW_TRANSACTIONS)       logSurface(this,"String_Node_Str" + mFrame.left + "String_Node_Str"+ mFrame.top+ "String_Node_Str"+ mFrame.width()+ "String_Node_Str"+ mFrame.height()+ "String_Node_Str"+ mAnimLayer+ "String_Node_Str",null);
    }
    Surface.openTransaction();
    try {
      try {
        mSurface.setPosition(mFrame.left + mXOffset,mFrame.top + mYOffset);
        mSurface.setLayer(mAnimLayer);
        mSurface.hide();
        if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_DITHER) != 0) {
          if (SHOW_TRANSACTIONS)           logSurface(this,"String_Node_Str",null);
          mSurface.setFlags(Surface.SURFACE_DITHER,Surface.SURFACE_DITHER);
        }
      }
 catch (      RuntimeException e) {
        Slog.w(TAG,"String_Node_Str" + w,e);
        reclaimSomeSurfaceMemoryLocked(this,"String_Node_Str");
      }
      mLastHidden=true;
    }
  finally {
      if (SHOW_TRANSACTIONS)       Slog.i(TAG,"String_Node_Str");
      Surface.closeTransaction();
    }
    if (localLOGV)     Slog.v(TAG,"String_Node_Str" + this);
  }
  return mSurface;
}

Fixed version (ground truth):
Surface createSurfaceLocked(){
  if (mSurface == null) {
    mReportDestroySurface=false;
    mSurfacePendingDestroy=false;
    mDrawPending=true;
    mCommitDrawPending=false;
    mReadyToShow=false;
    if (mAppToken != null) {
      mAppToken.allDrawn=false;
    }
    int flags=0;
    if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
      flags|=Surface.PUSH_BUFFERS;
    }
    if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SECURE) != 0) {
      flags|=Surface.SECURE;
    }
    if (DEBUG_VISIBILITY)     Slog.v(TAG,"String_Node_Str" + mSession.mSurfaceSession + "String_Node_Str"+ this+ "String_Node_Str"+ mFrame.width()+ "String_Node_Str"+ mFrame.height()+ "String_Node_Str"+ mAttrs.format+ "String_Node_Str"+ flags);
    int w=mFrame.width();
    int h=mFrame.height();
    if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
      w=mRequestedWidth;
      h=mRequestedHeight;
    }
    if (w <= 0)     w=1;
    if (h <= 0)     h=1;
    mSurfaceShown=false;
    mSurfaceLayer=0;
    mSurfaceAlpha=1;
    mSurfaceX=0;
    mSurfaceY=0;
    mSurfaceW=w;
    mSurfaceH=h;
    try {
      mSurface=new Surface(mSession.mSurfaceSession,mSession.mPid,mAttrs.getTitle().toString(),0,w,h,mAttrs.format,flags);
      if (SHOW_TRANSACTIONS)       Slog.i(TAG,"String_Node_Str" + mSurface + "String_Node_Str"+ mSession.mSurfaceSession+ "String_Node_Str"+ mSession.mPid+ "String_Node_Str"+ mAttrs.format+ "String_Node_Str"+ Integer.toHexString(flags)+ "String_Node_Str"+ this);
    }
 catch (    Surface.OutOfResourcesException e) {
      Slog.w(TAG,"String_Node_Str");
      reclaimSomeSurfaceMemoryLocked(this,"String_Node_Str");
      return null;
    }
catch (    Exception e) {
      Slog.e(TAG,"String_Node_Str",e);
      return null;
    }
    if (localLOGV)     Slog.v(TAG,"String_Node_Str" + mSurface + "String_Node_Str"+ mFrame.left+ "String_Node_Str"+ mFrame.top+ "String_Node_Str"+ mAnimLayer);
    if (SHOW_TRANSACTIONS) {
      Slog.i(TAG,"String_Node_Str");
      if (SHOW_TRANSACTIONS)       logSurface(this,"String_Node_Str" + mFrame.left + "String_Node_Str"+ mFrame.top+ "String_Node_Str"+ mFrame.width()+ "String_Node_Str"+ mFrame.height()+ "String_Node_Str"+ mAnimLayer+ "String_Node_Str",null);
    }
    Surface.openTransaction();
    try {
      try {
        mSurfaceX=mFrame.left + mXOffset;
        mSurfaceY=mFrame.top=mYOffset;
        mSurface.setPosition(mSurfaceX,mSurfaceY);
        mSurfaceLayer=mAnimLayer;
        mSurface.setLayer(mAnimLayer);
        mSurfaceShown=false;
        mSurface.hide();
        if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_DITHER) != 0) {
          if (SHOW_TRANSACTIONS)           logSurface(this,"String_Node_Str",null);
          mSurface.setFlags(Surface.SURFACE_DITHER,Surface.SURFACE_DITHER);
        }
      }
 catch (      RuntimeException e) {
        Slog.w(TAG,"String_Node_Str" + w,e);
        reclaimSomeSurfaceMemoryLocked(this,"String_Node_Str");
      }
      mLastHidden=true;
    }
  finally {
      if (SHOW_TRANSACTIONS)       Slog.i(TAG,"String_Node_Str");
      Surface.closeTransaction();
    }
    if (localLOGV)     Slog.v(TAG,"String_Node_Str" + this);
  }
  return mSurface;
}