Fix major mamory corruption problem.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32085 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2011-02-11 18:53:24 +00:00
parent f9f81837d6
commit 5c18f6ccbb
2 changed files with 16 additions and 9 deletions

View file

@ -1,5 +1,12 @@
2011-02-11 Richard Frith-Macdonald <rfm@gnu.org> 2011-02-11 Richard Frith-Macdonald <rfm@gnu.org>
* libs/base/trunk/Source/GSPrivate.h: Fixed the new GS_BEGINITEMBUF()
code ... was causing hard-to-track-down memory corruption which
unfortunately didn't show up in the testsuite (or I'd not have
re-comitted this code in the first place).
2_011-02-11 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSKeyValueObserving.m: Recommit * Source/NSKeyValueObserving.m: Recommit
Reviewed and tested. Reviewed and tested.
* Source/NAutoreleasePool.m: Make +initialize do nothing so that it * Source/NAutoreleasePool.m: Make +initialize do nothing so that it

View file

@ -96,17 +96,17 @@ typedef struct objc_category* Category;
#if __GNUC__ > 3 #if __GNUC__ > 3
__attribute__((unused)) static void GSFreeTempBuffer(void **b) __attribute__((unused)) static void GSFreeTempBuffer(void **b)
{ {
if (NULL != *b) free(*b); if (NULL != *b) free(*b);
} }
# define GS_BEGINITEMBUF(P, S, T) { \ # define GS_BEGINITEMBUF(P, S, T) { \
T _ibuf[GS_MAX_OBJECTS_FROM_STACK];\ T _ibuf[GS_MAX_OBJECTS_FROM_STACK];\
T *P = _ibuf;\ T *P = _ibuf;\
__attribute__((cleanup(GSFreeTempBuffer))) void *_base = 0;\ __attribute__((cleanup(GSFreeTempBuffer))) void *_base = 0;\
if (S > GS_MAX_OBJECTS_FROM_STACK)\ if (S > GS_MAX_OBJECTS_FROM_STACK)\
{\ {\
_base = malloc(S);\ _base = malloc((S) * sizeof(T));\
P = _base;\ P = _base;\
} }
#else #else
# define GS_BEGINITEMBUF(P, S, T) { \ # define GS_BEGINITEMBUF(P, S, T) { \
T _ibuf[(S) <= GS_MAX_OBJECTS_FROM_STACK ? (S) : 0]; \ T _ibuf[(S) <= GS_MAX_OBJECTS_FROM_STACK ? (S) : 0]; \