diff options
author | Adam Domurad <[email protected]> | 2013-07-30 13:49:13 -0400 |
---|---|---|
committer | Adam Domurad <[email protected]> | 2013-07-30 13:49:13 -0400 |
commit | 3a5331da7c7fa15f7c59bd38539a635206e75368 (patch) | |
tree | ee54fbf5d2407dba39d3cec57fde465e9a7ba120 /tests/cpp-unit-tests/browser_mock.cc | |
parent | c821809a6876465a504abcaa2ac1e6a448a4ea3f (diff) |
Fix many memory leaks due to utf8fromidentifier misuse
Diffstat (limited to 'tests/cpp-unit-tests/browser_mock.cc')
-rw-r--r-- | tests/cpp-unit-tests/browser_mock.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/cpp-unit-tests/browser_mock.cc b/tests/cpp-unit-tests/browser_mock.cc index e333be7..8724687 100644 --- a/tests/cpp-unit-tests/browser_mock.cc +++ b/tests/cpp-unit-tests/browser_mock.cc @@ -90,6 +90,15 @@ static NPObject* mock_createobject(NPP instance, NPClass* np_class) { return obj; } +static NPUTF8* mock_utf8fromidentifier(NPIdentifier id) { + // Treat NPIdentifier (== void pointer) as a pointer to characters for simplicity + const NPUTF8* str = (const NPUTF8*) id; + // We expect this string to be freed with 'memfree' + NPUTF8* copy = (NPUTF8*) mock_memalloc(strlen(str) + 1); + memcpy(copy, str, strlen(str) + 1); + return copy; +} + void browsermock_setup_functions() { memset(&browser_functions, 0, sizeof(NPNetscapeFuncs)); @@ -98,7 +107,8 @@ void browsermock_setup_functions() { browser_functions.createobject = &mock_createobject; browser_functions.retainobject = &mock_retainobject; - browser_functions.releaseobject= &mock_releaseobject; + browser_functions.releaseobject = &mock_releaseobject; + browser_functions.utf8fromidentifier = &mock_utf8fromidentifier; } void browsermock_clear_state() { |