ObjFW  Check-in [e9d48d0beb]

Overview
Comment:Call [super free] on error in init methods.

Reason is that - free might free stuff which is allocated during the
initialization, which might not be allocated when an error occurred.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e9d48d0beb030438b66db0bfede05348e6dd8d99263ac1829efaf333c92fe673
User & Date: js on 2009-05-01 18:15:32
Other Links: manifest | tags
Context
2009-05-01
19:38
Some tests were still using #import for C headers. Fixed. check-in: f198059455 user: js tags: trunk
18:15
Call [super free] on error in init methods. check-in: e9d48d0beb user: js tags: trunk
2009-04-28
20:31
Fix two missing spaces. check-in: 14f74f3c2f user: js tags: trunk
Changes

Modified src/OFArray.m from [91667fe0ee] to [5aad2dc149].

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
	Class c;

	self = [super init];

	if (is == 0) {
		c = isa;
		[self free];
		@throw [OFInvalidArgumentException newWithClass: c];
	}

	data = NULL;
	itemsize = is;
	items = 0;








|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
	Class c;

	self = [super init];

	if (is == 0) {
		c = isa;
		[super free];
		@throw [OFInvalidArgumentException newWithClass: c];
	}

	data = NULL;
	itemsize = is;
	items = 0;

Modified src/OFDictionary.m from [a34c760d2b] to [84c38f0c0c].

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

	size = 4096;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
	} @catch (OFException *e) {
		[self free];
		@throw e;
	}
	memset(data, 0, size);

	return self;
}

- initWithHashSize: (int)hashsize
{
	self = [super init];

	if (hashsize < 8 || hashsize > 31) {
		Class c = isa;
		[self free];
		@throw [OFInvalidArgumentException
			newWithClass: c
			 andSelector: _cmd];
	}

	size = (size_t)1 << hashsize;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
	} @catch (OFException *e) {
		[self free];
		@throw e;
	}
	memset(data, 0, size);

	return self;
}








|













|











|







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

	size = 4096;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
	} @catch (OFException *e) {
		[super free];
		@throw e;
	}
	memset(data, 0, size);

	return self;
}

- initWithHashSize: (int)hashsize
{
	self = [super init];

	if (hashsize < 8 || hashsize > 31) {
		Class c = isa;
		[super free];
		@throw [OFInvalidArgumentException
			newWithClass: c
			 andSelector: _cmd];
	}

	size = (size_t)1 << hashsize;

	@try {
		data = [self allocNItems: size
				withSize: sizeof(OFList*)];
	} @catch (OFException *e) {
		[super free];
		@throw e;
	}
	memset(data, 0, size);

	return self;
}

Modified src/OFString.m from [db633d72e6] to [8c5b52d99d].

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
				@throw [OFInvalidEncodingException
					newWithClass: c];
		}

		@try {
			string = [self allocWithSize: length + 1];
		} @catch (OFException *e) {
			[self free];
			@throw e;
		}
		memcpy(string, str, length + 1);
	}

	return self;
}







|







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
				@throw [OFInvalidEncodingException
					newWithClass: c];
		}

		@try {
			string = [self allocWithSize: length + 1];
		} @catch (OFException *e) {
			[super free];
			@throw e;
		}
		memcpy(string, str, length + 1);
	}

	return self;
}