memory management fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36842 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2013-07-06 05:27:59 +00:00
parent b71fde4e19
commit f8a14cae14
2 changed files with 55 additions and 20 deletions

View file

@ -1,3 +1,8 @@
2013-07-06 Richard Frith-Macdonald <rfm@gnu.org>
* Source/cifframe.m: Fix possible incorrect free of non-malloc'ed
memory.
2013-07-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSObject.m: Fix error creating instasnce when using the

View file

@ -259,8 +259,12 @@ cifframe_arg_addr(cifframe_t *cframe, int index)
ffi_type *
cifframe_type(const char *typePtr, const char **advance)
{
static ffi_type stypeNSPoint = { 0 };
static ffi_type stypeNSRange = { 0 };
static ffi_type stypeNSRect = { 0 };
static ffi_type stypeNSSize = { 0 };
const char *type;
ffi_type *ftype;
ffi_type *ftype = 0;
typePtr = objc_skip_type_qualifiers (typePtr);
type = typePtr;
@ -353,9 +357,9 @@ cifframe_type(const char *typePtr, const char **advance)
if (GSSelectorTypesMatch(typePtr - 1, @encode(NSRange)))
{
static ffi_type *elems[3];
static ffi_type stype = { 0 };
static ffi_type *ftype = &stypeNSRange;
if (stype.type == 0)
if (ftype->type == 0)
{
const char *t = @encode(NSUInteger);
@ -375,19 +379,18 @@ cifframe_type(const char *typePtr, const char **advance)
}
elems[1] = elems[0];
elems[2] = 0;
stype.elements = elems;
stype.type = FFI_TYPE_STRUCT;
ftype->elements = elems;
ftype->type = FFI_TYPE_STRUCT;
}
ftype = &stype;
typePtr = objc_skip_typespec (typePtr - 1);
break;
}
else if (GSSelectorTypesMatch(typePtr - 1, @encode(NSSize)))
else if (GSSelectorTypesMatch(typePtr - 1, @encode(NSPoint)))
{
static ffi_type *elems[3];
static ffi_type stype = { 0 };
static ffi_type *ftype = &stypeNSPoint;
if (stype.type == 0)
if (ftype->type == 0)
{
if (*@encode(CGFloat) == _C_DBL)
{
@ -399,30 +402,51 @@ cifframe_type(const char *typePtr, const char **advance)
}
elems[1] = elems[0];
elems[2] = 0;
stype.elements = elems;
stype.type = FFI_TYPE_STRUCT;
ftype->elements = elems;
ftype->type = FFI_TYPE_STRUCT;
}
typePtr = objc_skip_typespec (typePtr - 1);
break;
}
else if (GSSelectorTypesMatch(typePtr - 1, @encode(NSSize)))
{
static ffi_type *elems[3];
static ffi_type *ftype = &stypeNSSize;
if (ftype->type == 0)
{
if (*@encode(CGFloat) == _C_DBL)
{
elems[0] = &ffi_type_double;
}
else
{
elems[0] = &ffi_type_float;
}
elems[1] = elems[0];
elems[2] = 0;
ftype->elements = elems;
ftype->type = FFI_TYPE_STRUCT;
}
ftype = &stype;
typePtr = objc_skip_typespec (typePtr - 1);
break;
}
else if (GSSelectorTypesMatch(typePtr - 1, @encode(NSRect)))
{
static ffi_type *elems[3];
static ffi_type stype = { 0 };
static ffi_type *ftype = &stypeNSRect;
if (stype.type == 0)
if (ftype->type == 0)
{
/* An NSRect is an NSPoint and an NSSize, but those
* two structures are actually identical.
*/
elems[0] = cifframe_type(@encode(NSSize), NULL);
elems[1] = elems[0];
elems[1] = cifframe_type(@encode(NSPoint), NULL);
elems[2] = 0;
stype.elements = elems;
stype.type = FFI_TYPE_STRUCT;
ftype->elements = elems;
ftype->type = FFI_TYPE_STRUCT;
}
ftype = &stype;
typePtr = objc_skip_typespec (typePtr - 1);
break;
}
@ -497,8 +521,14 @@ cifframe_type(const char *typePtr, const char **advance)
NSCAssert(typePtr, @"End of signature while parsing");
if (align > max_align)
{
if (ftype && ftype->type == FFI_TYPE_STRUCT)
free(ftype);
if (ftype && ftype->type == FFI_TYPE_STRUCT
&& ftype != &stypeNSPoint
&& ftype != &stypeNSRange
&& ftype != &stypeNSRect
&& ftype != &stypeNSSize)
{
free(ftype);
}
ftype = local;
max_align = align;
}