diff --git a/ChangeLog b/ChangeLog index f20ac6f28..cc6aa74c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-10-08 Eric Wasylishen + + * Source/GSAvahiRunLoopIntegration.m: Fix some bugs: + - Remove an extra retain of the NSTimer which was leaking memory. + - When passed a NULL struct timeval * from avahi, invalidate + the timer and don't schedule a new one. + 2010-10-04 Richard Frith-Macdonald * Source/NSPredicate.m: Add simple implementation of diff --git a/Source/GSAvahiRunLoopIntegration.m b/Source/GSAvahiRunLoopIntegration.m index 1982c8fd9..14ff52127 100644 --- a/Source/GSAvahiRunLoopIntegration.m +++ b/Source/GSAvahiRunLoopIntegration.m @@ -221,27 +221,34 @@ [timer invalidate]; timer = nil; } - - timer = [[NSTimer timerWithTimeInterval: interval - target: self - selector: @selector(didTimeout:) - userInfo: nil - repeats: NO] retain]; + + // NOTE: the timer ivar is a weak reference; runloops retain their + // timers. + timer = [NSTimer timerWithTimeInterval: interval + target: self + selector: @selector(didTimeout:) + userInfo: nil + repeats: NO]; [[ctx runLoop] addTimer: timer forMode: [ctx mode]]; } - (void)setTimerToTimeval: (const struct timeval*)tv { - // Construct a NSTimeInterval for the timer: - NSTimeInterval interval = 0; - + // Invalidate the old timer + if (timer != nil) + { + [timer invalidate]; + timer = nil; + } + if (NULL != tv) { - interval = (NSTimeInterval)tv->tv_sec; + // Construct a NSTimeInterval for the timer: + NSTimeInterval interval = (NSTimeInterval)tv->tv_sec; interval += (NSTimeInterval)(tv->tv_usec / 1000000.0); + [self setTimerToInterval: interval]; } - [self setTimerToInterval: interval]; } - (id)initWithCallback: (AvahiTimeoutCallback)aCallback andContext: (GSAvahiRunLoopContext*)aCtx @@ -264,8 +271,8 @@ { if ([timer isValid]) { - [timer invalidate]; fireDate = [[timer fireDate] retain]; + [timer invalidate]; timer = nil; } }