aboutsummaryrefslogtreecommitdiffstats
path: root/lib/wx/c_src/wxe_impl.cpp
diff options
context:
space:
mode:
authorDan Gudmundsson <[email protected]>2010-01-19 14:15:31 +0000
committerErlang/OTP <[email protected]>2010-01-19 14:15:31 +0000
commitb0b1c57b2256c0081b8e43b0c8799c71e30016fe (patch)
treece71e3c8046bb2fcb72814a0f17c569ccc90cbe1 /lib/wx/c_src/wxe_impl.cpp
parent9ef7d5424fee7cd703f6fad30786358ec36a3749 (diff)
downloadotp-b0b1c57b2256c0081b8e43b0c8799c71e30016fe.tar.gz
otp-b0b1c57b2256c0081b8e43b0c8799c71e30016fe.tar.bz2
otp-b0b1c57b2256c0081b8e43b0c8799c71e30016fe.zip
Fixed a memory reference bug which caused unexplained {badarg, Int} exits.
You could get a reference to another applications memory, if wx had deleted that applications memory without the drivers knowledge about it, typically memory allocated by wx and not the application using classes where wx-driver can't override the desctructors. When wx allocated new memory and got a pointer to that memory, the wx-driver detected the same pointer and forwarded the old ref to erlang.
Diffstat (limited to 'lib/wx/c_src/wxe_impl.cpp')
-rw-r--r--lib/wx/c_src/wxe_impl.cpp57
1 files changed, 32 insertions, 25 deletions
diff --git a/lib/wx/c_src/wxe_impl.cpp b/lib/wx/c_src/wxe_impl.cpp
index d115bb2243..4486dff63b 100644
--- a/lib/wx/c_src/wxe_impl.cpp
+++ b/lib/wx/c_src/wxe_impl.cpp
@@ -1,19 +1,19 @@
/*
* %CopyrightBegin%
- *
- * Copyright Ericsson AB 2008-2009. All Rights Reserved.
- *
+ *
+ * Copyright Ericsson AB 2008-2010. All Rights Reserved.
+ *
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
* compliance with the License. You should have received a copy of the
* Erlang Public License along with this software. If not, it can be
* retrieved online at http://www.erlang.org/.
- *
+ *
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
- *
+ *
* %CopyrightEnd%
*/
@@ -615,28 +615,33 @@ int WxeApp::getRef(void * ptr, wxeMemEnv *memenv) {
ptrMap::iterator it = ptr2ref.find(ptr);
if(it != ptr2ref.end()) {
wxeRefData *refd = it->second;
- return refd->ref;
- } else { // New Ptr
- int ref;
- intList free = memenv->free;
-
- if(free.IsEmpty()) {
- ref = memenv->next++;
- } else {
- ref = free.Pop();
- };
- if(ref >= memenv->max) {
- memenv->max *= 2;
- memenv->ref2ptr =
- (void **) driver_realloc(memenv->ref2ptr,memenv->max * sizeof(void*));
- }
+ if(refd->memenv == memenv) {
+ // Found it return
+ return refd->ref;
+ } // else
+ // Old reference to deleted object, release old and recreate in current memenv.
+ clearPtr(ptr);
+ }
+ int ref;
+ intList free = memenv->free;
- memenv->ref2ptr[ref] = ptr;
- ptr2ref[ptr] = new wxeRefData(ref, 0, false, memenv);
- return ref;
+ if(free.IsEmpty()) {
+ ref = memenv->next++;
+ } else {
+ ref = free.Pop();
+ };
+ if(ref >= memenv->max) {
+ memenv->max *= 2;
+ memenv->ref2ptr =
+ (void **) driver_realloc(memenv->ref2ptr,memenv->max * sizeof(void*));
}
+
+ memenv->ref2ptr[ref] = ptr;
+ ptr2ref[ptr] = new wxeRefData(ref, 0, false, memenv);
+ return ref;
}
+
void WxeApp::clearPtr(void * ptr) {
ptrMap::iterator it;
it = ptr2ref.find(ptr);
@@ -697,13 +702,15 @@ void WxeApp::clearPtr(void * ptr) {
void * WxeApp::getPtr(char * bp, wxeMemEnv *memenv) {
int index = *(int *) bp;
- if(!memenv)
+ if(!memenv) {
throw wxe_badarg(index);
+ }
void * temp = memenv->ref2ptr[index];
if((index < memenv->next) && ((index == 0) || (temp > NULL)))
return temp;
- else
+ else {
throw wxe_badarg(index);
+ }
}
void WxeApp::registerPid(char * bp, ErlDrvTermData pid, wxeMemEnv * memenv) {