diff --git a/ChangeLog b/ChangeLog index 65e44e887..cd6ebb3c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-02-11 Richard Frith-Macdonald + + * Source/GSICUString.m: + Fix leak spotted by static analyser. + 2011-02-11 12:06 David Chisnall * libs/base/trunk/Source/GSPrivate.h: Added exception-safe version diff --git a/Source/GSICUString.h b/Source/GSICUString.h index 434ccab0c..a82447a51 100644 --- a/Source/GSICUString.h +++ b/Source/GSICUString.h @@ -11,6 +11,7 @@ * contents directly. */ UText* UTextInitWithNSString(UText *txt, NSString *str); + /** * Initialises a UText structure with an NSMutableString. If txt is NULL, then * this allocates a new structure on the heap, otherwise it fills in the @@ -23,6 +24,7 @@ UText* UTextInitWithNSString(UText *txt, NSString *str); * reflected in the underlying NSMutableString. */ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); + /** * GSUTextString is an NSString subclass that is backed by a libicu UText * structure. This class is intended to be used when returning UText created @@ -30,9 +32,9 @@ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); */ @interface GSUTextString : NSString { - @public - /** The UText structure containing the libicu string interface. */ - UText txt; + @public + /** The UText structure containing the libicu string interface. */ + UText txt; } @end @@ -43,9 +45,9 @@ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); */ @interface GSUTextMutableString : NSMutableString { - @public - /** The UText structure containing the libicu string interface. */ - UText txt; + @public + /** The UText structure containing the libicu string interface. */ + UText txt; } @end @@ -54,10 +56,10 @@ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); */ static inline void free_string(unichar **buf) { - if (0 != *buf) - { - free(*buf); - } + if (0 != *buf) + { + free(*buf); + } } /** @@ -68,12 +70,12 @@ static inline void free_string(unichar **buf) * Buffers created in this way are exception safe when using native exceptions. */ #define TEMP_BUFFER(name, size)\ - __attribute__((cleanup(free_string))) unichar *name ##_onheap = 0;\ - unichar name ## _onstack[64 / sizeof(unichar)];\ - unichar *name = name ## _onstack;\ - if (size > 64)\ - {\ - name ## _onheap = malloc(size);\ - name = name ## _onheap;\ - } + __attribute__((cleanup(free_string))) unichar *name ##_onheap = 0;\ + unichar name ## _onstack[64 / sizeof(unichar)];\ + unichar *name = name ## _onstack;\ + if (size > 64)\ + {\ + name ## _onheap = malloc(size);\ + name = name ## _onheap;\ + } diff --git a/Source/GSICUString.m b/Source/GSICUString.m index c4e811da4..201557dca 100644 --- a/Source/GSICUString.m +++ b/Source/GSICUString.m @@ -263,12 +263,19 @@ UTextNSMutableStringClone(UText *dest, UErrorCode *status) { NSMutableString *str = (NSMutableString*)src->p; + UText *txt; if (deep) { str = [str mutableCopy]; + txt = UTextInitWithNSMutableString(dest, str); + [str release]; } - return UTextInitWithNSMutableString(dest, str); + else + { + txt = UTextInitWithNSMutableString(dest, str); + } + return txt; } /**