Thread: Crash during displaying drop-down menu for server

Crash during displaying drop-down menu for server

From
Tomasz Rybak
Date:
I updated my sources to 4512, compiled and installed.
When I run pgAdmin, and try to right-click on server
in databases tree, pgAdmin crashes.

After little debugging I discovered, that problem is in
src/main/events.cpp, frmMain::doPopup.

pgAdmin crashes in line 466:
if (mil.Item(newItemPos)->GetData()->GetId() == newItem->GetId())

It's caused because newItem is NULL, and it isn't received in line 458
wxMenuItem *newItem=treeContextMenu->FindItem(newMenuFactory->GetId());
What's strange, wxASSERT from next line isn't even called (at least not
under GDB). I compiled using standard Debian setting, only added -ggdb
for compiler and removed dh_strip from pkg/debian/rules.

Message from GDB:
#0  0x0807a083 in frmMain::doPopup (this=0x87680f0, win=0x8d0c640,
point=
      {x = 145, y = 43}, object=0x8699340) at ./main/events.cpp:466
466             if (mil.Item(newItemPos)->GetData()->GetId() ==
newItem->GetId())

When I double-click on database in tree view (so pgAdmin is connected
to it) and after that I right-click on it's entry, pgAdmin doesn't
crash.

--
Tomasz Rybak <bogomips@post.pl>


Re: Crash during displaying drop-down menu for server

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgadmin-hackers-owner@postgresql.org
> [mailto:pgadmin-hackers-owner@postgresql.org] On Behalf Of
> Tomasz Rybak
> Sent: 06 October 2005 19:18
> To: pgAdmin Hackers
> Subject: [pgadmin-hackers] Crash during displaying drop-down
> menu for server
>
> I updated my sources to 4512, compiled and installed.
> When I run pgAdmin, and try to right-click on server
> in databases tree, pgAdmin crashes.
>
> After little debugging I discovered, that problem is in
> src/main/events.cpp, frmMain::doPopup.
>
> pgAdmin crashes in line 466:
> if (mil.Item(newItemPos)->GetData()->GetId() == newItem->GetId())
>
> It's caused because newItem is NULL, and it isn't received in line 458
> wxMenuItem
> *newItem=treeContextMenu->FindItem(newMenuFactory->GetId());
> What's strange, wxASSERT from next line isn't even called (at
> least not
> under GDB). I compiled using standard Debian setting, only added -ggdb
> for compiler and removed dh_strip from pkg/debian/rules.
>
> Message from GDB:
> #0  0x0807a083 in frmMain::doPopup (this=0x87680f0, win=0x8d0c640,
> point=
>       {x = 145, y = 43}, object=0x8699340) at ./main/events.cpp:466
> 466             if (mil.Item(newItemPos)->GetData()->GetId() ==
> newItem->GetId())
>
> When I double-click on database in tree view (so pgAdmin is connected
> to it) and after that I right-click on it's entry, pgAdmin doesn't
> crash.

Yes, I can confirm this on Windows. I think the problem actually comes
from line 458:

    wxMenuItem
*newItem=treeContextMenu->FindItem(newMenuFactory->GetId());
    wxASSERT(newItem);

Where newItem is null if not connected to the server. I'm not sure how
to fix this - Andreas, can you look at it please?

Thanks, Dave.

Re: Crash during displaying drop-down menu for

From
Tomasz Rybak
Date:
I think I know what's causing this crash.
However, I don't know where to fix it.
I'll be writing about file src/main/events.cpp.

When I right-click, frmMain::doPopup is called.
It creates new treeContextMenu, and appends all active
options from main menu. Here's how it looks just before crash:
Item 1176
0 1160 O
1 -2
2 1177 P
3 1182 U
4 -2
5 1195 W

(it's from code:
printf("Item %i\n", newMenuFactory->GetId());
size_t i;
wxMenuItemList j = treeContextMenu->GetMenuItems();
for (i=0 ; i < j.GetCount() ; i++)
{
    printf("%i %i %s\n", i, j.Item(i)->GetData()->GetId(),
j.Item(i)->GetData()->GetText().c_str());
}

It looks for menu item 1176 (New object), but this item is inactive.
However after starting pgAdmin it is active, made it so by code:
src/frm/frmMain.cpp, line 172:
newMenuFactory = new dummyActionFactory(menuFactories);     //
placeholder
where "New objects" submenu will be inserted
    editMenu->Append(newMenuFactory->GetId(), _("New &Object"), newMenu,
_("Create a new object."));

It's mede inactive after clicking on server, and remains so until
connecting to server. Then menu looks like that:
Item 1176
0 1160 O
1 -2
2 1176 N
3 1178 R
4 1182 U
5 -2
6 1195 W
And now New Object is active, so it's included in treeContextMenu.

I tried to disable deactivating newMenu by commenting out line 341:
editMenu->Enable(newMenuFactory->GetId(), false);
but it didn't work.

--
Tomasz Rybak <bogomips@post.pl>


Re: Crash during displaying drop-down menu for

From
Andreas Pflug
Date:
Tomasz Rybak wrote:
> I think I know what's causing this crash.
> However, I don't know where to fix it.

Things are quite easy after all.
That lengthy code in line 460ff is for some beautifying of "new xxx"
stuff in the context menu. If there's no object creatable, the "New
Object" menu will be disabled, and so newItem will receive 0 by design
(thus wxASSERT is wrong). In that case, most of the code can be skipped.

Fixed in svn, thanks for reporting.

Regards,
Andreas