Use reallocf() to simplify some logic.

MFC after:	2 weeks
This commit is contained in:
John Baldwin 2009-12-29 15:48:04 +00:00
parent 5d2874abdd
commit c34169d468
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=201202

View File

@ -493,7 +493,7 @@ search(u_long addr, action_fn *action)
{
int mib[6];
size_t needed;
char *lim, *buf, *newbuf, *next;
char *lim, *buf, *next;
struct rt_msghdr *rtm;
struct sockaddr_inarp *sin2;
struct sockaddr_dl *sdl;
@ -516,13 +516,9 @@ search(u_long addr, action_fn *action)
return 0;
buf = NULL;
for (;;) {
newbuf = realloc(buf, needed);
if (newbuf == NULL) {
if (buf != NULL)
free(buf);
buf = reallocf(buf, needed);
if (buf == NULL)
errx(1, "could not reallocate memory");
}
buf = newbuf;
st = sysctl(mib, 6, buf, &needed, NULL, 0);
if (st == 0 || errno != ENOMEM)
break;