From 9d5bbc80904d3a589b871a40d8cc6d82bd2c271e Mon Sep 17 00:00:00 2001 From: Dwight Date: Wed, 13 May 2009 11:42:48 -0400 Subject: [PATCH] fix up free() old defensive code --- db/db.vcproj | 12 ++++++++++++ scripting/engine_spidermonkey.cpp | 2 ++ stdafx.h | 3 +++ 3 files changed, 17 insertions(+) diff --git a/db/db.vcproj b/db/db.vcproj index b78d0e03781..a5392ade05d 100644 --- a/db/db.vcproj +++ b/db/db.vcproj @@ -1773,6 +1773,18 @@ RelativePath="..\scripting\engine_spidermonkey.cpp" > + + + + + diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index a1eca14ef48..ae2dad81441 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -75,6 +75,8 @@ namespace mongo { string toString( JSString * so ){ jschar * s = JS_GetStringChars( so ); size_t srclen = JS_GetStringLength( so ); + if( srclen == 0 ) + return ""; size_t len = srclen * 2; char * dst = (char*)malloc( len ); diff --git a/stdafx.h b/stdafx.h index 8d412fcebde..4269eda3900 100644 --- a/stdafx.h +++ b/stdafx.h @@ -315,8 +315,11 @@ namespace mongo { #if defined(_WIN32) #define strcasecmp _stricmp inline void our_debug_free(void *p) { +#if 0 +// this is not safe if you malloc < 4 bytes so we don't use anymore unsigned *u = (unsigned *) p; u[0] = 0xEEEEEEEE; +#endif free(p); } #define free our_debug_free