ObjFW  Check-in [4d5b2623c8]

Overview
Comment:OFData: Fix memory leak
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4d5b2623c83f07ef3726d5dc9f56eed428b8f458ae29fedc52a436192650de3b
User & Date: js on 2020-11-04 23:11:54
Other Links: manifest | tags
Context
2020-11-04
23:18
Remove of_free() check-in: 3d8286feee user: js tags: trunk
23:11
OFData: Fix memory leak check-in: 4d5b2623c8 user: js tags: trunk
2020-11-02
22:13
OFString+PathAdditions: Fix typo check-in: 1042afedd9 user: js tags: trunk
Changes

Modified src/OFData.m from [bf7091f2d8] to [e268178a8e].

244
245
246
247
248
249
250
251

252

253
254
255




256
257
258



259
260
261
262
263







264
265
266
267
268
269
270
244
245
246
247
248
249
250

251
252
253



254
255
256
257
258


259
260
261
262




263
264
265
266
267
268
269
270
271
272
273
274
275
276







-
+

+
-
-
-
+
+
+
+

-
-
+
+
+

-
-
-
-
+
+
+
+
+
+
+







		stream = [URLHandler openItemAtURL: URL
					      mode: @"r"];

		_itemSize = 1;
		_count = 0;

		pageSize = [OFSystemInfo pageSize];
		buffer = [self allocMemoryWithSize: pageSize];
		buffer = of_malloc(1, pageSize);

		@try {
		while (!stream.atEndOfStream) {
			size_t length = [stream readIntoBuffer: buffer
							length: pageSize];
			while (!stream.atEndOfStream) {
				size_t length = [stream
				    readIntoBuffer: buffer
					    length: pageSize];

			if (SIZE_MAX - _count < length)
				@throw [OFOutOfRangeException exception];
				if (SIZE_MAX - _count < length)
					@throw [OFOutOfRangeException
					    exception];

			_items = [self resizeMemory: _items
					       size: _count + length];
			memcpy(_items + _count, buffer, length);
			_count += length;
				_items = [self resizeMemory: _items
						       size: _count + length];
				memcpy(_items + _count, buffer, length);
				_count += length;
			}
		} @finally {
			of_free(buffer);
		}

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}