NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Query about xmalloc.c (cp is used after free())
Hi All,
I have a query regarding xmalloc.c in NetBSD. I use netbsd for
my system and in the ld i found that in xmalloc.c the following
code, where the pointer cp is used after xfree().
% cat src/libexec/ld.elf_so/xmalloc.c
337 irealloc(void *cp, size_t nbytes)
338 {
339 register u_int onb;
340 register int i;
341 union overhead *op;
342 char *res;
:
:
:
362 /* avoid the copy if same size block */
363 if (i) {
364 i = 1 << (i + 2);
365 if (i < pagesz)
366 i -= sizeof (*op) + RSLOP;
367 else
368 i += pagesz - sizeof (*op) - RSLOP;
369 }
370 if (nbytes <= onb && nbytes > i) {
371 #ifdef RCHECK
372 op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1);
373 *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC;
374 #endif
375 return(cp);
376 } else
377 xfree(cp);
378 if ((res = imalloc(nbytes)) == NULL)
379 return (NULL);
380 if (cp != res) /* common optimization if "compacting" */
381 memcpy(res, cp, (nbytes < onb) ? nbytes : onb);
382 return (res);
383 }
384
in the above code at 377 xfree(cp) is done and at 381 cp is used to
copy to the result.
Is this OK?
Please tell me if there are any issues,
thanks in advance,
--
Jagadiswara
Home |
Main Index |
Thread Index |
Old Index