ObjFW  Diff

Differences From Artifact [02f24ce790]:

To Artifact [3718c4ff22]:

  • File src/OFObject.m — part of check-in [6e357d636d] at 2009-10-19 08:29:45 on branch trunk — 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. (user: js, size: 11011) [annotate] [blame] [check-ins using]


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];