| 279 | | i_free(loc) |
| 280 | | char *loc; |
| 281 | | { |
| 282 | | struct glob *ob; |
| 283 | | struct glob *preob; |
| 284 | | int rs; |
| 285 | | char *ptr = loc; |
| 286 | | struct glob **he; |
| 287 | | int i; |
| 288 | | |
| 289 | | |
| 290 | | |
| 291 | | if (firsttime) { |
| 292 | | char *s = "i_free: called before i_malloc?\n"; |
| 293 | | SWRITE(debfd, s);
|
| 294 | | i_choke(); |
| 295 | | return 0; |
| 296 | | } |
| 297 | | |
| 298 | | |
| 299 | | |
| 300 | | he = &hashtbl[HASH(loc)];
|
| 301 | | for (preob = 0, ob = *he; ob && ob->base != loc; preob = ob, ob = ob->next); |
| 302 | | if (!ob) { |
| 303 | | (void)sprintf(msbuf, "i_free: bogus loc=0x%lx\n", (long) loc); |
| 304 | | (void)SWRITE(debfd, msbuf);
|
| 305 | | i_choke(); |
| 306 | | return 0; |
| 307 | | } |
| 308 | | rs = ob->rst; |
| 309 | | |
| 310 | | |
| 311 | | |
| 312 | | for (i = ob->lop, ptr -= i; i > 0; i--) |
| 313 | | if ((0xff & (int)(*ptr++)) != (0xff & NEXTRN(rs))) {
|
| 314 | | (void)sprintf(msbuf, "i_free: scribbled in 0x%lx[%d]\n", |
| 315 | | (long) loc, -i); |
| 316 | | (void)SWRITE(debfd, msbuf);
|
| 317 | | i_choke(); |
| 318 | | } |
| 319 | | for (i = ob->hip, ptr += ob->len; i > 0; i--) |
| 320 | | if ((0xff & (int)(*ptr++)) != (0xff & NEXTRN(rs))) {
|
| 321 | | (void)sprintf(msbuf, "i_free: scribbled in 0x%lx[%d+%d]\n", |
| 322 | | (long) loc, ob->len, ob->hip - i); |
| 323 | | (void)SWRITE(debfd, msbuf);
|
| 324 | | i_choke(); |
| 325 | | } |
| 326 | | |
| 327 | | |
| 328 | | |
| 329 | | #if ZEROONFREE
|
| 330 | | BZERO(loc - ob->lop, ob->len + ob->lop + ob->hip);
|
| 331 | | #endif |
| 332 | | free(loc - ob->lop); |
| 333 | | totlnbyts -= ob->len; |
| 334 | | |
| 335 | | |
| 336 | | |
| 337 | | if (preob) |
| 338 | | preob->next = ob->next; |
| 339 | | else |
| 340 | | *he = ob->next; |
| 341 | | #if STATICGLOBS > 0
|
| 342 | | ob->next = globfl; |
| 343 | | globfl = ob; |
| 344 | | globavail++; |
| 345 | | #else |
| 346 | | free((char*)ob); |
| 347 | | #endif |
| 348 | | return 0; |
| 349 | | } |