Fix some leaks

This commit is contained in:
rfm 2024-06-21 15:53:55 +01:00
parent 4233f6a9d6
commit 50e1575b8d
6 changed files with 78 additions and 46 deletions

View file

@ -1,3 +1,12 @@
2024-06-21 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/AGSOutput.m:
* Tools/AGSParser.m:
* Tools/autogsdoc.m:
* Tools/make_strings/make_strings.m:
* Tools/plutil.m:
Fix various memory leaks.
2024-06-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/Unicode.m:

View file

@ -1498,7 +1498,8 @@ static BOOL snuggleStart(NSString *t)
* or end tag, or one of the whitespace separated words.
* What about str?
*/
data = [[NSMutableData alloc] initWithLength: l * sizeof(unichar)];
data = AUTORELEASE([[NSMutableData alloc]
initWithLength: l * sizeof(unichar)]);
ptr = buf = [data mutableBytes];
[str getCharacters: buf];
end = buf + l;
@ -2341,7 +2342,7 @@ static BOOL snuggleStart(NSString *t)
* No pre-existing file, and no blank template available ...
* Generate a standard template.
*/
str = [[NSMutableString alloc] initWithCapacity: 1024];
str = [NSMutableString stringWithCapacity: 1024];
[str appendString: @"<?xml version=\"1.0\"?>\n"];
[str appendString: @"<!DOCTYPE gsdoc PUBLIC "];

View file

@ -2849,23 +2849,23 @@ try:
}
if ([token isEqual: @"private"])
{
ASSIGN(validity, token);
validity = AUTORELEASE(RETAIN(token));
shouldDocument = documentInstanceVariables
&& documentAllInstanceVariables;
}
else if ([token isEqual: @"protected"])
{
ASSIGN(validity, token);
validity = AUTORELEASE(RETAIN(token));
shouldDocument = documentInstanceVariables;
}
else if ([token isEqual: @"package"])
{
ASSIGN(validity, token);
validity = AUTORELEASE(RETAIN(token));
shouldDocument = documentInstanceVariables;
}
else if ([token isEqual: @"public"])
{
ASSIGN(validity, token);
validity = AUTORELEASE(RETAIN(token));
shouldDocument = documentInstanceVariables;
}
else
@ -2938,7 +2938,7 @@ fail:
NSMutableArray *a = nil;
NSString *name;
dict = [[NSMutableDictionary alloc] initWithCapacity: 4];
dict = AUTORELEASE([[NSMutableDictionary alloc] initWithCapacity: 4]);
name = [self parseIdentifier];
if (nil == name)
{
@ -3035,11 +3035,11 @@ fail:
}
else
{
DESTROY(dict);
dict = nil;
}
RELEASE(a);
[self setStandards: dict];
return AUTORELEASE(dict);
return dict;
}
- (NSMutableDictionary*) parseMethodIsDeclaration: (BOOL)flag
@ -4094,6 +4094,7 @@ countAttributes(NSSet *keys, NSDictionary *a)
if (hadOstep)
{
[self log: @"multiple grouped OS_API_VERSION() calls"];
RELEASE(top);
return [self skipRemainderOfLine];
}
hadOstep = YES;
@ -4107,6 +4108,7 @@ countAttributes(NSSet *keys, NSDictionary *a)
if (hadGstep)
{
[self log: @"multiple grouped GS_API_VERSION() calls"];
RELEASE(top);
return [self skipRemainderOfLine];
}
hadGstep = YES;
@ -4308,6 +4310,7 @@ countAttributes(NSSet *keys, NSDictionary *a)
if (pos < length && (buffer[pos] == ',' || buffer[pos] == ';'))
{
[self skipStatement];
DESTROY(dict);
return nil;
}

View file

@ -896,7 +896,7 @@ main(int argc, char **argv, char **env)
declared = [defs stringForKey: @"Declared"];
project = [defs stringForKey: @"Project"];
refsName = [[project stringByAppendingPathExtension: @"igsdoc"] copy];
refsName = [project stringByAppendingPathExtension: @"igsdoc"];
headerDirectory = [defs stringForKey: @"HeaderDirectory"];
if (headerDirectory == nil)
@ -1005,13 +1005,13 @@ main(int argc, char **argv, char **env)
refsFile = [documentationDirectory
stringByAppendingPathComponent: project];
refsFile = [refsFile stringByAppendingPathExtension: @"igsdoc"];
projectRefs = [AGSIndex new];
projectRefs = AUTORELEASE([AGSIndex new]);
originalIndex = nil;
rDate = [NSDate distantPast];
if ([mgr isReadableFileAtPath: refsFile] == YES)
{
originalIndex
= [[NSDictionary alloc] initWithContentsOfFile: refsFile];
= AUTORELEASE([[NSDictionary alloc] initWithContentsOfFile: refsFile]);
if (originalIndex == nil)
{
NSLog(@"Unable to read project file '%@'", refsFile);
@ -1105,7 +1105,7 @@ main(int argc, char **argv, char **env)
NSString *k;
unsigned length;
ms = [[NSMutableString alloc] initWithContentsOfFile: path];
ms = [NSMutableString stringWithContentsOfFile: path];
if (ms == nil)
{
NSLog(@"Cleaning ... failed to read '%@'", path);
@ -1231,7 +1231,8 @@ main(int argc, char **argv, char **env)
if ([sFiles count] == 0 && [gFiles count] == 0 && [hFiles count] == 0)
{
NSLog(@"No .h, .m, .c, .gsdoc, or .html filename arguments found ... giving up");
NSLog(@"No .h, .m, .c, .gsdoc, or .html filename arguments found"
@" ... giving up");
return 1;
}
@ -1590,6 +1591,7 @@ main(int argc, char **argv, char **env)
DESTROY(pool);
DESTROY(parser);
DESTROY(output);
AUTORELEASE(informalProtocols);
}
/*
@ -1680,6 +1682,7 @@ main(int argc, char **argv, char **env)
{
NSLog(@"not a gsdoc document - because name node is %@",
[root name]);
DESTROY(merged);
return 1;
}
@ -1708,7 +1711,6 @@ main(int argc, char **argv, char **env)
if (informalProtocols != nil)
{
[projectRefs addInformalProtocols: informalProtocols];
DESTROY(informalProtocols);
if (verbose)
{
NSLog(@"Added informal protocols into projectRefs");
@ -1732,7 +1734,7 @@ main(int argc, char **argv, char **env)
DESTROY(merged);
}
globalRefs = [AGSIndex new];
globalRefs = AUTORELEASE([AGSIndex new]);
/*
* 8) If we are either generating html output, or relocating existing
@ -1900,7 +1902,6 @@ main(int argc, char **argv, char **env)
if (verbose)
{
NSLog(@"Merged indexes into globalRefs from %@", merged);
}
}

View file

@ -600,7 +600,7 @@ int main(int argc, char **argv)
return 1;
}
source_entries = [[NSMutableDictionary alloc] init];
source_entries = [NSMutableDictionary dictionary];
error = 0;
{
int i;

View file

@ -151,7 +151,7 @@ parseQuotedString(const char *, size_t *);
NSArray *
parseKeyPath(const char *keypath)
{
NSMutableArray *res = [[NSMutableArray alloc] init];
NSMutableArray *res = [NSMutableArray array];
NSString *key = nil;
size_t i;
size_t j;
@ -185,7 +185,7 @@ parseKeyPath(const char *keypath)
break;
}
}
return [res copy];
return AUTORELEASE([res copy]);
}
/**
@ -249,15 +249,20 @@ plIndexKeypath(id obj, NSString *keypath, int depthOffset)
id
parseValue(NSString *type, NSString *value)
{
id result;
if ([type isEqual: @"-plist"])
return [value propertyList];
{
result = [value propertyList];
}
else if ([type isEqual: @"-xml"] || [type isEqual: @"-date"])
{
NSData *mydata =
[value dataUsingEncoding: [NSString defaultCStringEncoding]];
NSPropertyListFormat aFormat;
NSError * anError;
id result = [NSPropertyListSerialization
NSError *anError;
result = [NSPropertyListSerialization
propertyListWithData: mydata
options: NSPropertyListMutableContainersAndLeaves
format: &aFormat
@ -265,39 +270,52 @@ parseValue(NSString *type, NSString *value)
if (result == nil)
{
GSPrintf(stderr, @"Parsing plist %@: %@\n", value, anError);
return nil;
}
else if ([type isEqual: @"-xml"]
&& aFormat != NSPropertyListXMLFormat_v1_0)
GSPrintf(stderr,
@"Warning: parsing XML plist %@: Not an XML (fmt %d)\n", value,
aFormat);
&& aFormat != NSPropertyListXMLFormat_v1_0)
{
GSPrintf(stderr,
@"Warning: parsing XML plist %@: Not an XML (fmt %d)\n", value,
aFormat);
}
else if ([type isEqual: @"-date"]
&& ![result isKindOfClass: [NSDate class]])
GSPrintf(stderr, @"Warning: parsing date %@: Not a date (got %@)\n",
value, result);
return result;
&& ![result isKindOfClass: [NSDate class]])
{
GSPrintf(stderr, @"Warning: parsing date %@: Not a date (got %@)\n",
value, result);
}
}
else if ([type isEqual: @"-bool"])
return [NSNumber
numberWithBool: ([value isEqual: @"YES"] || [value isEqual: @"true"])];
{
result = [NSNumber numberWithBool:
([value isEqual: @"YES"] || [value isEqual: @"true"])];
}
else if ([type isEqual: @"-integer"])
return [[NSNumber alloc] initWithLongLong: [value longLongValue]];
{
result = [NSNumber numberWithLongLong: [value longLongValue]];
}
else if ([type isEqual: @"-float"])
// We do a step further than NSPropertyList.m and probably Apple,
// since notsupporting inf and nan is a bad look
// (No hex literals for now unless someone really wants it)
return [[NSNumber alloc] initWithDouble: strtod([value cString], 0)];
{
/*
* We do a step further than NSPropertyList.m and probably Apple,
* since notsupporting inf and nan is a bad look
* (No hex literals for now unless someone really wants it)
*/
result = [NSNumber numberWithDouble: strtod([value cString], 0)];
}
else if ([type isEqual: @"-data"])
return [[NSData alloc]
initWithBase64EncodedData: [value
dataUsingEncoding: [NSString
defaultCStringEncoding]]
options: NSDataBase64DecodingIgnoreUnknownCharacters];
{
result = AUTORELEASE([[NSData alloc] initWithBase64EncodedData:
[value dataUsingEncoding: [NSString defaultCStringEncoding]]
options: NSDataBase64DecodingIgnoreUnknownCharacters]);
}
else
GSPrintf(stderr, @"Unrecognized type %@\n", type);
{
GSPrintf(stderr, @"Unrecognized type %@\n", type);
result = nil;
}
return nil;
return result;
}
#define SELFMAP(Name) NINT(Name), NSTR(#Name)