Memory leak fix and tidyup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20360 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-11-19 09:41:34 +00:00
parent 1ddff14944
commit 5e95fdf285
3 changed files with 131 additions and 110 deletions

View file

@ -1,3 +1,12 @@
2004-11-19 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/pl.m: Make code conform to gnu coding standards.
* Source/NSRunLoop.m: ([runMode:beforeDate:]) add autorelease pool
to retain old behavior where anything inside a runloop is
automatically in the scope of an autorelease pool, and will not
be leaked by autoreleasing. Fixes obscure problems with the last
limitDateForMode changes.
2004-11-18 Gregory John Casamento <greg_casamento@yahoo.com>
* Tools/pl.m: Added a tool I wrote a while back which is an

View file

@ -1743,6 +1743,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
while (GSIArrayCount(timers) != 0)
{
NSTimer *min_timer = GSIArrayItemAtIndex(timers, 0).obj;
if (timerInvalidated(min_timer) == YES)
{
GSIArrayRemoveItemAtIndex(timers, 0);
@ -1750,9 +1751,10 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
continue;
}
if (!when)
if (when == nil)
{
when = [timerDate(min_timer) copy];
}
if ([timerDate(min_timer) timeIntervalSinceNow] > 0)
{
break;
@ -1849,13 +1851,14 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
* that the housekeeper timer does not keep the runloop
* active. It's a special case set up in NSThread.m
*/
if (min_watcher == nil && when)
if (min_watcher == nil && when != nil)
{
unsigned count = GSIArrayCount(timers);
while (count-- > 1)
{
NSTimer *tmp = GSIArrayItemAtIndex(timers, 0).obj;
if (timerInvalidated(tmp) == YES)
{
GSIArrayRemoveItemAtIndex(timers, count);
@ -1885,7 +1888,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
* watcher (or leave it as the date of the earliest timer if that is
* before the watchers limit).
*/
if (when)
if (when != nil)
{
if (min_watcher != nil
&& [min_watcher->_date compare: when] == NSOrderedAscending)
@ -1894,8 +1897,10 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
when = min_watcher->_date;
}
else
{
AUTORELEASE(when);
}
}
else if (min_watcher != nil)
{
when = min_watcher->_date;
@ -2030,7 +2035,8 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
*/
- (BOOL) runMode: (NSString*)mode beforeDate: (NSDate*)date
{
id d;
CREATE_AUTORELEASE_POOL(arp);
NSDate *d;
NSAssert(mode != nil, NSInvalidArgumentException);
@ -2046,6 +2052,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
{
GSNotifyASAP();
}
RELEASE(arp);
return NO;
}
@ -2064,7 +2071,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
[self acceptInputForMode: mode beforeDate: d];
RELEASE(d);
RELEASE(arp);
return YES;
}

View file

@ -41,8 +41,9 @@ void create_output( id propertyList )
if (outputIndex == NSNotFound)
{
const char *buffer = [[propertyList description] cString];
NSData *outputData = [NSData dataWithBytes: buffer length: strlen(buffer)];
NSData *outputData;
outputData = [NSData dataWithBytes: buffer length: strlen(buffer)];
// setup the file handle.
fileHandle = [NSFileHandle fileHandleWithStandardOutput];
// Send the data to stdout
@ -106,12 +107,13 @@ NSData *read_input()
char *buffer = 0;
// set up the file handle.
fileHandle = [NSFileHandle fileHandleForReadingAtPath: [arguments objectAtIndex: inputIndex+1]];
fileHandle = [NSFileHandle fileHandleForReadingAtPath:
[arguments objectAtIndex: inputIndex+1]];
// read in the serialized plist.
serializedData = [fileHandle readDataToEndOfFile];
[fileHandle closeFile];
propertyList = [NSDeserializer deserializePropertyListFromData: serializedData
mutableContainers: NO];
propertyList = [NSDeserializer deserializePropertyListFromData:
serializedData mutableContainers: NO];
if (propertyList != nil)
{
buffer = (char *)[[propertyList description] cString];
@ -119,7 +121,8 @@ NSData *read_input()
}
else
{
NSLog(@"%@ is not a serialized property list.", [arguments objectAtIndex: inputIndex+1]);
NSLog(@"%@ is not a serialized property list.",
[arguments objectAtIndex: inputIndex+1]);
}
}
@ -150,9 +153,11 @@ int main (int argc, const char *argv[])
else
{
puts("pl {-input <serialized_file>} {-output <serialized_file>}");
puts(" - Reads an ASCII property list from standard in, or a serialized one");
puts(
" - Reads an ASCII property list from standard in, or a serialized one");
puts(" if -input is specified.");
puts(" - Writes an ASCII propert list to standard out, or a serialized one");
puts(
" - Writes an ASCII propert list to standard out, or a serialized one");
puts(" if -output is specified.");
}