@@ -110,10 +110,22 @@ for (i = 0; i < count; i++) { if ([objs[i] isEqual: obj]) { OFObject *obj = objs[i]; [array removeItemAtIndex: i]; [obj release]; + + /* + * We need to get the C array again as it might have + * been relocated. We also need to adjust the count + * as otherwise we would have an out of bounds access. + * As another object will be at the current index now, + * we also need to handle the same index again, thus we + * decrease it. + */ + objs = [array cArray]; + count--; + i--; } } return self; } @@ -125,10 +137,22 @@ for (i = 0; i < count; i++) { if (objs[i] == obj) { [array removeItemAtIndex: i]; [obj release]; + + /* + * We need to get the C array again as it might have + * been relocated. We also need to adjust the count + * as otherwise we would have an out of bounds access. + * As another object will be at the current index now, + * we also need to handle the same index again, thus we + * decrease it. + */ + objs = [array cArray]; + count--; + i--; } } return self; }