if( menu && menuHandle ) {
if (menu) {
void nsPreviousMenuStackUnwind(nsIMenu * aMenuJustBuilt, MenuHandle aMenuHandleJustBuilt){  PRBool shouldReleaseMenubar = PR_FALSE;    //printf("PreviousMenuStackUnwind called \n");  //printf("%d items on gPreviousMenuStack \n", gPreviousMenuStack.Count());  while (gPreviousMenuHandleStack.Count()) {    nsIMenu * menu = (nsIMenu *) gPreviousMenuStack[gPreviousMenuStack.Count() - 1];    MenuHandle menuHandle = (MenuHandle) gPreviousMenuHandleStack[gPreviousMenuHandleStack.Count() - 1];        //printf("  gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count());    //printf("  gPreviousMenuHandleStack.Count() = %d \n", gPreviousMenuHandleStack.Count());               if( menu && menuHandle ) {            if( menuHandle != aMenuHandleJustBuilt ) {                   nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(menu));        if(listener) {          nsMenuEvent mevent;          mevent.message = NS_MENU_SELECTED;          mevent.eventStructType = NS_MENU_EVENT;          mevent.point.x = 0;          mevent.point.y = 0;          mevent.widget = nsnull;          mevent.time = PR_IntervalNow();          mevent.mCommand = (PRUint32) nsnull;                    // UNDO          listener->MenuDeselected(mevent);                    gPreviousMenuStack.RemoveElementAt(gPreviousMenuStack.Count() - 1);          NS_IF_RELEASE(menu);          shouldReleaseMenubar = PR_TRUE;                    //printf("%d items now on gPreviousMenuStack \n", gPreviousMenuStack.Count());          gPreviousMenuHandleStack.RemoveElementAt(gPreviousMenuHandleStack.Count() - 1);                  }  	  }   	  else {          //printf("  gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count());          //printf("  gPreviousMenuHandleStack.Count() = %d \n", gPreviousMenuHandleStack.Count());   	    return;  	  }	  }  }    // relinquish hold of the menubar _after_ releasing the menu so it can finish  // unregistering itself.  if ( shouldReleaseMenubar )    gPreviousMenuBar = nsnull;    //printf("  gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count());  //printf("  gPreviousMenuHandleStack.Count() = %d \n", gPreviousMenuHandleStack.Count()); }