Fix many memory leaks #7

Merged
Letterus merged 2 commits from js/objgtkgen:fix-memleaks into main 9 months ago
  1. 7
      src/GIR/GIRApi.m
  2. 5
      src/GIR/GIRArray.m
  3. 2
      src/GIR/GIRBase.m
  4. 9
      src/GIR/GIRClass.m
  5. 13
      src/GIR/GIRConstant.m
  6. 13
      src/GIR/GIRConstructor.m
  7. 14
      src/GIR/GIRDoc.m
  8. 19
      src/GIR/GIREnumeration.m
  9. 20
      src/GIR/GIRField.m
  10. 13
      src/GIR/GIRFunction.m
  11. 14
      src/GIR/GIRImplements.m
  12. 13
      src/GIR/GIRInterface.m
  13. 16
      src/GIR/GIRMember.m
  14. 15
      src/GIR/GIRMethod.m
  15. 8
      src/GIR/GIRNamespace.m
  16. 18
      src/GIR/GIRParameter.m
  17. 7
      src/GIR/GIRPrerequisite.m
  18. 23
      src/GIR/GIRProperty.m
  19. 15
      src/GIR/GIRReturnValue.m
  20. 14
      src/GIR/GIRType.m
  21. 14
      src/GIR/GIRVarargs.m
  22. 14
      src/GIR/GIRVirtualMethod.m
  23. 11
      src/Generator/OGTKClass.m
  24. 25
      src/Generator/OGTKClassWriter.m
  25. 10
      src/Gir2Objc.m

7
src/GIR/GIRApi.m

@ -52,7 +52,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

5
src/GIR/GIRArray.m

@ -54,8 +54,11 @@
{
self = [self init];
if (self) {
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;

2
src/GIR/GIRBase.m

@ -101,7 +101,7 @@ LogLevel _logLevel = Info;
- (void)logUnknownElement:(OFString*)element
{
if (self.unknownElements == nil) {
self.unknownElements = [[OFMutableDictionary alloc] init];
self.unknownElements = [OFMutableDictionary dictionary];
}
OFString* hopefullyUniqueKey =

9
src/GIR/GIRClass.m

@ -69,7 +69,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -98,7 +103,7 @@
} else if ([key isEqual:@"abstract"]) {
self.abstract = [value isEqual:@"1"];
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"constructor"]) {
[self processArrayOrDictionary:value
withClass:[GIRConstructor class]

13
src/GIR/GIRConstant.m

@ -57,7 +57,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -85,9 +90,11 @@
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
} else if ([key isEqual:@"doc-deprecated"]) {
self.docDeprecated = [[GIRDoc alloc] initWithDictionary:value];
self.docDeprecated =
[[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"type"]) {
self.type = [[GIRType alloc] initWithDictionary:value];
self.type =
[[[GIRType alloc] initWithDictionary:value] autorelease];
} else {
[self logUnknownElement:key];
}

13
src/GIR/GIRConstructor.m

@ -63,7 +63,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -94,12 +99,12 @@
} else if ([key isEqual:@"throws"]) {
self.throws = [value isEqual:@"1"];
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"doc-deprecated"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"return-value"]) {
self.returnValue =
[[GIRReturnValue alloc] initWithDictionary:value];
[[[GIRReturnValue alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"parameters"]) {
for (OFString* paramKey in value) {
if ([paramKey isEqual:@"parameter"]) {

14
src/GIR/GIRDoc.m

@ -37,12 +37,7 @@
{
self = [super init];
@try {
elementTypeName = @"GIRDoc";
} @catch (id e) {
[self release];
@throw e;
}
elementTypeName = @"GIRDoc";
return self;
}
@ -51,7 +46,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

19
src/GIR/GIREnumeration.m

@ -51,6 +51,7 @@
[self release];
@throw e;
}
return self;
}
@ -58,7 +59,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -83,9 +89,10 @@
} else if ([key isEqual:@"deprecated"]) {
self.deprecated = [value isEqual:@"1"];
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"doc-deprecated"]) {
self.docDeprecated = [[GIRDoc alloc] initWithDictionary:value];
self.docDeprecated =
[[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"member"]) {
[self processArrayOrDictionary:value
withClass:[GIRMember class]
@ -110,7 +117,8 @@
}
if ([object isKindOfClass:[OFDictionary class]]) {
[members addObject:[[GIRMember alloc] initWithDictionary:object]];
[members addObject:[[[GIRMember alloc] initWithDictionary:object]
autorelease]];
}
}
@ -124,7 +132,8 @@
}
if ([object isKindOfClass:[OFDictionary class]]) {
[functions addObject:[[GIRFunction alloc] initWithDictionary:object]];
[functions addObject:[[[GIRFunction alloc] initWithDictionary:object]
autorelease]];
}
}

20
src/GIR/GIRField.m

@ -40,12 +40,7 @@
{
self = [super init];
@try {
elementTypeName = @"GIRField";
} @catch (id e) {
[self release];
@throw e;
}
elementTypeName = @"GIRField";
return self;
}
@ -54,7 +49,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -75,9 +75,11 @@
} else if ([key isEqual:@"bits"]) {
self.bits = [value longLongValue];
} else if ([key isEqual:@"type"]) {
self.type = [[GIRType alloc] initWithDictionary:value];
self.type =
[[[GIRType alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"array"]) {
self.array = [[GIRArray alloc] initWithDictionary:value];
self.array =
[[[GIRArray alloc] initWithDictionary:value] autorelease];
} else {
[self logUnknownElement:key];
}

13
src/GIR/GIRFunction.m

@ -63,7 +63,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -92,12 +97,12 @@
} else if ([key isEqual:@"throws"]) {
self.throws = [value isEqual:@"1"];
} else if ([key isEqual:@"doc-deprecated"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"return-value"]) {
self.returnValue =
[[GIRReturnValue alloc] initWithDictionary:value];
[[[GIRReturnValue alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"parameters"]) {
for (OFString* paramKey in value) {
if ([paramKey isEqual:@"parameter"]) {

14
src/GIR/GIRImplements.m

@ -35,12 +35,7 @@
{
self = [super init];
@try {
elementTypeName = @"GIRImplements";
} @catch (id e) {
[self release];
@throw e;
}
elementTypeName = @"GIRImplements";
return self;
}
@ -49,7 +44,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

13
src/GIR/GIRInterface.m

@ -61,7 +61,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -83,7 +88,7 @@
} else if ([key isEqual:@"c:symbol-prefix"]) {
self.cSymbolPrefix = value;
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"fields"]) {
[self processArrayOrDictionary:value
withClass:[GIRField class]
@ -101,8 +106,8 @@
withClass:[GIRProperty class]
andArray:properties];
} else if ([key isEqual:@"prerequisite"]) {
self.prerequisite =
[[GIRPrerequisite alloc] initWithDictionary:value];
self.prerequisite = [[[GIRPrerequisite alloc]
initWithDictionary:value] autorelease];
} else {
[self logUnknownElement:key];
}

16
src/GIR/GIRMember.m

@ -38,12 +38,7 @@
{
self = [super init];
@try {
elementTypeName = @"GIRMember";
} @catch (id e) {
[self release];
@throw e;
}
elementTypeName = @"GIRMember";
return self;
}
@ -52,7 +47,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -71,7 +71,7 @@
} else if ([key isEqual:@"value"]) {
self.theValue = [value longLongValue];
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else {
[self logUnknownElement:key];
}

15
src/GIR/GIRMethod.m

@ -65,7 +65,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -92,11 +97,13 @@
} else if ([key isEqual:@"version"]) {
self.version = value;
} else if ([key isEqual:@"return-value"]) {
self.returnValue = [[GIRReturnValue alloc] initWithDictionary:value];
self.returnValue =
[[[GIRReturnValue alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"doc-deprecated"]) {
self.docDeprecated = [[GIRDoc alloc] initWithDictionary:value];
self.docDeprecated =
[[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"deprecated"]) {
self.deprecated = [value isEqual:@"1"];
} else if ([key isEqual:@"deprecated-version"]) {

8
src/GIR/GIRNamespace.m

@ -53,6 +53,7 @@
[self release];
@throw e;
}
return self;
}
@ -60,7 +61,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

18
src/GIR/GIRParameter.m

@ -60,7 +60,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -91,13 +96,16 @@
} else if ([key isEqual:@"destroy"]) {
self.destroy = [value longLongValue];
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"type"]) {
self.type = [[GIRType alloc] initWithDictionary:value];
self.type =
[[[GIRType alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"array"]) {
self.array = [[GIRArray alloc] initWithDictionary:value];
self.array =
[[[GIRArray alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"varargs"]) {
self.varargs = [[GIRVarargs alloc] initWithDictionary:value];
self.varargs =
[[[GIRVarargs alloc] initWithDictionary:value] autorelease];
} else {
[self logUnknownElement:key];
}

7
src/GIR/GIRPrerequisite.m

@ -52,7 +52,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

23
src/GIR/GIRProperty.m

@ -51,12 +51,7 @@
{
self = [super init];
@try {
elementTypeName = @"GIRProperty";
} @catch (id e) {
[self release];
@throw e;
}
elementTypeName = @"GIRProperty";
return self;
}
@ -65,7 +60,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -88,9 +88,11 @@
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
} else if ([key isEqual:@"doc-deprecated"]) {
self.docDeprecated = [[GIRDoc alloc] initWithDictionary:value];
self.docDeprecated =
[[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"type"]) {
self.type = [[GIRType alloc] initWithDictionary:value];
self.type =
[[[GIRType alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"allow-none"]) {
self.allowNone = [value isEqual:@"1"];
} else if ([key isEqual:@"construct-only"]) {
@ -104,7 +106,8 @@
} else if ([key isEqual:@"writable"]) {
self.writable = value;
} else if ([key isEqual:@"array"]) {
self.array = [[GIRArray alloc] initWithDictionary:value];
self.array =
[[[GIRArray alloc] initWithDictionary:value] autorelease];
} else {
[self logUnknownElement:key];
}

15
src/GIR/GIRReturnValue.m

@ -52,7 +52,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
@ -68,11 +73,13 @@
} else if ([key isEqual:@"transfer-ownership"]) {
self.transferOwnership = value;
} else if ([key isEqual:@"doc"]) {
self.doc = [[GIRDoc alloc] initWithDictionary:value];
self.doc = [[[GIRDoc alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"type"]) {
self.type = [[GIRType alloc] initWithDictionary:value];
self.type =
[[[GIRType alloc] initWithDictionary:value] autorelease];
} else if ([key isEqual:@"array"]) {
self.array = [[GIRArray alloc] initWithDictionary:value];
self.array =
[[[GIRArray alloc] initWithDictionary:value] autorelease];
} else {
[self logUnknownElement:key];
}

14
src/GIR/GIRType.m

@ -36,12 +36,7 @@
{
self = [super init];
@try {
elementTypeName = @"GIRType";
} @catch (id e) {
[self release];
@throw e;
}
elementTypeName = @"GIRType";
return self;
}
@ -50,7 +45,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

14
src/GIR/GIRVarargs.m

@ -33,12 +33,7 @@
{
self = [super init];
@try {
elementTypeName = @"GIRVarargs";
} @catch (id e) {
[self release];
@throw e;
}
elementTypeName = @"GIRVarargs";
return self;
}
@ -47,7 +42,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

14
src/GIR/GIRVirtualMethod.m

@ -33,12 +33,7 @@
{
self = [super init];
@try {
elementTypeName = @"GIRVirtualMethod";
} @catch (id e) {
[self release];
@throw e;
}
elementTypeName = @"GIRVirtualMethod";
return self;
}
@ -47,7 +42,12 @@
{
self = [self init];
[self parseDictionary:dict];
@try {
[self parseDictionary:dict];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

11
src/Generator/OGTKClass.m

@ -36,9 +36,14 @@
{
self = [super init];
constructors = [[OFMutableArray alloc] init];
functions = [[OFMutableArray alloc] init];
methods = [[OFMutableArray alloc] init];
@try {
constructors = [[OFMutableArray alloc] init];
functions = [[OFMutableArray alloc] init];
methods = [[OFMutableArray alloc] init];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}

25
src/Generator/OGTKClassWriter.m

@ -283,31 +283,26 @@
+ (OFString*)generateCParameterListString:(OFArray*)params
{
int i;
OFMutableString* paramsOutput = [[OFMutableString alloc] init];
OFMutableString* paramsOutput = [OFMutableString string];
if (params != nil && [params count] > 0) {
OGTKParameter* p;
for (i = 0; i < [params count]; i++) {
p = [params objectAtIndex:i];
[paramsOutput appendString:[OGTKUtil convertType:[p type]
withName:[p name]
toType:[p cType]]];
size_t i = 0, count = params.count;
for (OGTKParameter* param in params) {
[paramsOutput appendString:[OGTKUtil convertType:param.type
withName:param.name
toType:param.cType]];
if (i < [params count] - 1) {
[paramsOutput appendString:@", "];
}
}
if (i++ < count - 1)
[paramsOutput appendString:@", "];
}
return [paramsOutput autorelease];
return paramsOutput;
}
+ (OFString*)generateCParameterListWithInstanceString:(OFString*)instanceType
andParams:(OFArray*)params
{
int i;
OFMutableString* paramsOutput = [[OFMutableString alloc] init];
OFMutableString* paramsOutput = [OFMutableString string];
[paramsOutput appendString:[OGTKUtil selfTypeMethodCall:instanceType]];

10
src/Gir2Objc.m

@ -34,7 +34,8 @@
{
*girDict = nil;
OFString* girContents = [[OFString alloc] initWithContentsOfFile:girFile];
OFString* girContents =
[[[OFString alloc] initWithContentsOfFile:girFile] autorelease];
if (girContents == nil) {
@throw [[OFReadFailedException alloc] initWithObject:girFile
@ -240,9 +241,10 @@
[objcMeth setCReturnType:meth.returnValue.type.cType];
}
OFMutableArray* paramArray = [[OFMutableArray alloc] init];
OFMutableArray* paramArray = [OFMutableArray array];
for (GIRParameter* param in meth.parameters) {
OGTKParameter* objcParam = [[OGTKParameter alloc] init];
OGTKParameter* objcParam =
[[[OGTKParameter alloc] init] autorelease];
if (param.type == nil && param.array != nil) {
[objcParam setCType:param.array.cType];
@ -252,10 +254,8 @@
[objcParam setCName:param.name];
[paramArray addObject:objcParam];
[objcParam release];
}
[objcMeth setParameters:paramArray];
[paramArray release];
[cgtkClass addMethod:objcMeth];
[objcMeth release];

Loading…
Cancel
Save