ObjFW  Check-in [6e357d636d]

Overview
Comment:Fix a bug in -[freeMemory:].

This could be an out of bounds write if the last element is free'd,
as i is pointing to the last element then, which does not exist then
anymore, as it was already resized. Now, it is set before resizing.

Additionally, if the realloc to make it smaller fails, we just ignore
that now - it will still work, as we set the correct size before
resizing.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6e357d636d5c53a62c678f013a9b09295f829372f99f2d3328796aed649adf3d
User & Date: js on 2009-10-19 08:29:45
Other Links: manifest | tags
Context
2009-10-19
08:31
Add plugin support for Win32. check-in: 3194cede14 user: js tags: trunk
08:29
Fix a bug in -[freeMemory:]. check-in: 6e357d636d user: js tags: trunk
2009-10-18
19:32
Only cancel a thread on -[dealloc] if it's still running. check-in: 19a1167518 user: js tags: trunk
Changes

Modified src/OFObject.m from [02f24ce790] to [3718c4ff22].

407
408
409
410
411
412
413




414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

				PRE_IVAR->memchunks = NULL;
				PRE_IVAR->memchunks_size = 0;

				return self;
			}





			if (OF_UNLIKELY((memchunks = realloc(
			    PRE_IVAR->memchunks, memchunks_size *
			    sizeof(void*))) == NULL))
				return self;

			free(ptr);
			PRE_IVAR->memchunks = memchunks;
			PRE_IVAR->memchunks[i] = last;
			PRE_IVAR->memchunks_size = memchunks_size;

			return self;
		}
	}

	@throw [OFMemoryNotPartOfObjectException newWithClass: isa
						      pointer: ptr];







>
>
>
>





<

<
<







407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422

423


424
425
426
427
428
429
430

				PRE_IVAR->memchunks = NULL;
				PRE_IVAR->memchunks_size = 0;

				return self;
			}

			free(ptr);
			PRE_IVAR->memchunks[i] = last;
			PRE_IVAR->memchunks_size = memchunks_size;

			if (OF_UNLIKELY((memchunks = realloc(
			    PRE_IVAR->memchunks, memchunks_size *
			    sizeof(void*))) == NULL))
				return self;


			PRE_IVAR->memchunks = memchunks;



			return self;
		}
	}

	@throw [OFMemoryNotPartOfObjectException newWithClass: isa
						      pointer: ptr];