From 9f0e6770e1c7dfe6905177f834e339941f7d5677 Mon Sep 17 00:00:00 2001 From: Robbie Hanson Date: Wed, 28 Mar 2012 13:42:07 -0700 Subject: [PATCH] Fixing thread safety issue and potential memory leak in DDLogMessage. Fixes issue #21 --- Lumberjack/DDLog.h | 14 +++----------- Lumberjack/DDLog.m | 24 ++++++------------------ 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/Lumberjack/DDLog.h b/Lumberjack/DDLog.h index 43547b229..809dfed4b 100755 --- a/Lumberjack/DDLog.h +++ b/Lumberjack/DDLog.h @@ -425,14 +425,6 @@ NSString *DDExtractFileNameWithoutExtension(const char *filePath, BOOL copy); char *queueLabel; NSString *threadName; id tag; // For 3rd party extensions to the framework, where flags and contexts aren't enough. - -// The private variables below are only calculated if needed. -// You should use the public methods to access this information. - -@private - NSString *threadID; - NSString *fileName; - NSString *methodName; } /** @@ -457,18 +449,18 @@ NSString *DDExtractFileNameWithoutExtension(const char *filePath, BOOL copy); * Returns the threadID as it appears in NSLog. * That is, it is a hexadecimal value which is calculated from the machThreadID. **/ -@property (nonatomic, readonly) NSString *threadID; +- (NSString *)threadID; /** * Convenience property to get just the file name, as the file variable is generally the full file path. * This method does not include the file extension, which is generally unwanted for logging purposes. **/ -@property (nonatomic, readonly) NSString *fileName; +- (NSString *)fileName; /** * Returns the function variable in NSString form. **/ -@property (nonatomic, readonly) NSString *methodName; +- (NSString *)methodName; @end diff --git a/Lumberjack/DDLog.m b/Lumberjack/DDLog.m index b91c04429..a8b47601f 100755 --- a/Lumberjack/DDLog.m +++ b/Lumberjack/DDLog.m @@ -806,32 +806,20 @@ - (id)initWithLogMsg:(NSString *)msg - (NSString *)threadID { - if (threadID == nil) - { - threadID = [[NSString alloc] initWithFormat:@"%x", machThreadID]; - } - - return threadID; + return [[NSString alloc] initWithFormat:@"%x", machThreadID]; } - (NSString *)fileName { - if (fileName == nil && file != NULL) - { - fileName = DDExtractFileNameWithoutExtension(file, NO); - } - - return fileName; + return DDExtractFileNameWithoutExtension(file, NO); } - (NSString *)methodName { - if (methodName == nil && function != NULL) - { - methodName = [[NSString alloc] initWithUTF8String:function]; - } - - return methodName; + if (function == NULL) + return nil; + else + return [[NSString alloc] initWithUTF8String:function]; } - (void)dealloc