From 28337668d76e51751cd849f4711f0a26f7c104bd Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 21 Feb 2008 22:14:11 +0000 Subject: [PATCH] fixed free bug git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1608 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-core/NGExtensions/ChangeLog | 5 ++++ .../FdExt.subproj/NSString+Escaping.m | 23 ++++++++++--------- sope-core/NGExtensions/Version | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index f54aba74..2bf42ebb 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,8 @@ +2008-02-21 Helge Hess + + * FdExt.subproj/NSString+Escaping.m: fixed a free() bug introduced in + the unichar conversion of v4.7.197 (v4.7.200) + 2008-02-21 Helge Hess * FdExt.subproj/NGPropertyListParser.m: fixed NSException not to use diff --git a/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m b/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m index e31957e4..21f6b588 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m @@ -29,20 +29,20 @@ // Unicode! unichar *src; unichar *buffer; - int pos = 0; + int len, pos, srcIdx; NSString *s; - if ((pos = [self length]) == 0) + if ((len = [self length]) == 0) return @""; - - src = malloc(sizeof(unichar) * (pos + 2)); + + src = malloc(sizeof(unichar) * (len + 2)); [self getCharacters:src]; - src[pos] = 0; // zero-terminate + src[len] = 0; // zero-terminate - buffer = malloc(sizeof(unichar) * ((pos * 2) + 1)); + buffer = malloc(sizeof(unichar) * ((len * 2) + 1)); - for (pos = 0; *src != 0; pos++, src++) { - switch (*src) { + for (pos = 0, srcIdx = 0; srcIdx < len; pos++, srcIdx++) { + switch (src[srcIdx]) { case '\n': buffer[pos] = '\\'; pos++; buffer[pos] = 'n'; @@ -57,15 +57,16 @@ break; default: - buffer[pos] = *src; + buffer[pos] = src[srcIdx]; break; } } buffer[pos] = '\0'; s = [NSString stringWithCharacters:buffer length:pos]; - free(buffer); buffer = NULL; - free(src); src = NULL; + + if (buffer != NULL) { free(buffer); buffer = NULL; } + if (src != NULL) { free(src); src = NULL; } return s; } diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index d282e4a0..1f300e3b 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=199 +SUBMINOR_VERSION:=200 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39 -- 2.39.5