aboutsummaryrefslogtreecommitdiffstats
path: root/lib/wx/c_src
diff options
context:
space:
mode:
authorDan Gudmundsson <[email protected]>2013-10-30 16:46:54 +0100
committerDan Gudmundsson <[email protected]>2013-10-30 16:46:54 +0100
commitc054ac3d4df7fe8b2f58204e677f275bd8f0e60c (patch)
tree178e2dd83ca426d08d767be91a664b2bf6153e25 /lib/wx/c_src
parent1d7472911e14e4885c9111aa21fc201c397be20f (diff)
downloadotp-c054ac3d4df7fe8b2f58204e677f275bd8f0e60c.tar.gz
otp-c054ac3d4df7fe8b2f58204e677f275bd8f0e60c.tar.bz2
otp-c054ac3d4df7fe8b2f58204e677f275bd8f0e60c.zip
wx: Fix cleanup of event handlers
Event handlers was not removed after objects/process had been delete/died, which causes memory leakage and that fun's was kept in the wx_server process. Code that might be purged and the server died.
Diffstat (limited to 'lib/wx/c_src')
-rw-r--r--lib/wx/c_src/gen/wxe_events.cpp2
-rw-r--r--lib/wx/c_src/gen/wxe_funcs.cpp14
-rw-r--r--lib/wx/c_src/wxe_events.h39
-rw-r--r--lib/wx/c_src/wxe_impl.cpp20
4 files changed, 44 insertions, 31 deletions
diff --git a/lib/wx/c_src/gen/wxe_events.cpp b/lib/wx/c_src/gen/wxe_events.cpp
index a6a37cb37f..fb3a065448 100644
--- a/lib/wx/c_src/gen/wxe_events.cpp
+++ b/lib/wx/c_src/gen/wxe_events.cpp
@@ -346,7 +346,7 @@ bool sendevent(wxEvent *event, ErlDrvTermData port)
rt.addAtom((char*)"wx");
rt.addInt((int) event->GetId());
- rt.addRef(getRef((void *)(cb->obj), memenv), cb->class_name);
+ rt.addRef(cb->obj, cb->class_name);
rt.addExt2Term(cb->user_data);
switch(Etype->cID) {
case 164: {// wxCommandEvent
diff --git a/lib/wx/c_src/gen/wxe_funcs.cpp b/lib/wx/c_src/gen/wxe_funcs.cpp
index 2d8dbb242b..ae8b1fd8b1 100644
--- a/lib/wx/c_src/gen/wxe_funcs.cpp
+++ b/lib/wx/c_src/gen/wxe_funcs.cpp
@@ -93,13 +93,13 @@ case 100: { // wxEvtHandler::Connect
int eventType = wxeEventTypeFromAtom(bp); bp += *eventTypeLen;
char *class_name = bp; bp+= *class_nameLen;
if(eventType > 0 ) {
- wxeCallbackData * Evt_cb = new wxeCallbackData(Ecmd.caller,(void *) This,
- class_name,*fun_cb,
- *skip, userData);
- This->Connect((int) *winid,(int) *lastId,eventType,
- (wxObjectEventFunction)(wxEventFunction) &wxeEvtListener::forward,
- Evt_cb, Listener);
- rt.addAtom("ok");
+ wxeCallbackData * Evt_cb = new wxeCallbackData(Ecmd.caller,getRef(This, memenv),
+ class_name,*fun_cb,
+ *skip, userData, Listener);
+ This->Connect((int) *winid,(int) *lastId,eventType,
+ (wxObjectEventFunction)(wxEventFunction) &wxeEvtListener::forward,
+ Evt_cb, Listener);
+ rt.addAtom("ok");
} else {
rt.addAtom("badarg");
rt.addAtom("event_type");
diff --git a/lib/wx/c_src/wxe_events.h b/lib/wx/c_src/wxe_events.h
index 6bbb0dfa13..718e0ad120 100644
--- a/lib/wx/c_src/wxe_events.h
+++ b/lib/wx/c_src/wxe_events.h
@@ -30,6 +30,20 @@ public:
int cID;
};
+/* One EvtListener per listening erlang process */
+/* If callbacks are used the receiver is wxe_master process */
+/* and a wxeEvtListener pre callback is registered */
+class wxeEvtListener : public wxEvtHandler
+{
+ public:
+ wxeEvtListener(ErlDrvTermData Thisport) : port(Thisport)
+ {}
+ // {fprintf(stderr, "Creating %x\r\n", (unsigned int) this); fflush(stderr);}
+ ~wxeEvtListener() {}
+ void forward(wxEvent& event);
+ ErlDrvTermData port;
+};
+
void initEventTable();
int wxeEventTypeFromAtom(char *etype_atom);
@@ -37,32 +51,17 @@ int wxeEventTypeFromAtom(char *etype_atom);
class wxeCallbackData : public wxObject
{
public:
- wxeCallbackData(ErlDrvTermData caller, void *req, char *req_type,
- int funcb, int skip_ev, wxeErlTerm * userData);
+ wxeCallbackData(ErlDrvTermData caller, int req, char *req_type,
+ int funcb, int skip_ev, wxeErlTerm * userData,
+ wxeEvtListener *handler_cb);
~wxeCallbackData();
+ wxeEvtListener * handler;
ErlDrvTermData listener;
int fun_id;
- void * obj;
+ int obj;
char class_name[40];
int skip;
wxeErlTerm * user_data;
};
-/* One EvtListener per listening erlang process */
-/* If callbacks are used the receiver is wxe_master process */
-/* and a wxeEvtListener pre callback is registered */
-class wxeEvtListener : public wxEvtHandler
-{
-public:
- wxeEvtListener(ErlDrvTermData Thisport) : port(Thisport)
- {}
- // {fprintf(stderr, "Creating %x\r\n", (unsigned int) this); fflush(stderr);}
- void forward(wxEvent& event);
- ~wxeEvtListener() {
- ((WxeApp *)wxTheApp)->clearPtr(this);
- // fprintf(stderr, "Deleteing %x\r\n", (unsigned int) this); fflush(stderr);
- };
- ErlDrvTermData port;
-};
-
#endif
diff --git a/lib/wx/c_src/wxe_impl.cpp b/lib/wx/c_src/wxe_impl.cpp
index 8adec4be07..4968075659 100644
--- a/lib/wx/c_src/wxe_impl.cpp
+++ b/lib/wx/c_src/wxe_impl.cpp
@@ -880,8 +880,9 @@ wxETreeItemData::~wxETreeItemData()
* CallbackData *
* ****************************************************************************/
-wxeCallbackData::wxeCallbackData(ErlDrvTermData caller,void * req, char *req_type,
- int funcb, int skip_ev, wxeErlTerm * userData)
+wxeCallbackData::wxeCallbackData(ErlDrvTermData caller, int req, char *req_type,
+ int funcb, int skip_ev, wxeErlTerm * userData,
+ wxeEvtListener *handler_cb)
: wxObject()
{
listener = caller;
@@ -890,13 +891,26 @@ wxeCallbackData::wxeCallbackData(ErlDrvTermData caller,void * req, char *req_typ
strcpy(class_name, req_type);
skip = skip_ev;
user_data = userData;
+ handler = handler_cb;
}
wxeCallbackData::~wxeCallbackData() {
- // fprintf(stderr, "CBD Deleteing %x %s\r\n", (unsigned int) this, class_name); fflush(stderr);
+ // fprintf(stderr, "CBD Deleteing %p %s\r\n", this, class_name); fflush(stderr);
if(user_data) {
delete user_data;
}
+ ptrMap::iterator it;
+ it = ((WxeApp *)wxTheApp)->ptr2ref.find(handler);
+ if(it != ((WxeApp *)wxTheApp)->ptr2ref.end()) {
+ wxeRefData *refd = it->second;
+ wxeReturn rt = wxeReturn(WXE_DRV_PORT, refd->memenv->owner, false);
+ rt.addAtom("wx_delete_cb");
+ rt.addInt(fun_id);
+ rt.addRef(refd->ref, "wxeEvtListener");
+ rt.addRef(obj, class_name);
+ rt.addTupleCount(4);
+ rt.send();
+ }
}
/* ****************************************************************************