Date: Fri, 09 Aug 2002 09:11:02 +0200 From: Poul-Henning Kamp <phk@critter.freebsd.dk> To: "Andrey A. Chernov" <ache@nagual.pp.ru> Cc: current@freebsd.org Subject: Re: phk malloc() sometimes forget to set errno Message-ID: <10593.1028877062@critter.freebsd.dk> In-Reply-To: Your message of "Thu, 08 Aug 2002 03:27:52 %2B0400." <20020807232750.GA1168@nagual.pp.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <20020807232750.GA1168@nagual.pp.ru>, "Andrey A. Chernov" writes:
>I found at least one case:
Try this patch:
Index: malloc.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.70
diff -u -r1.70 malloc.c
--- malloc.c 30 May 2002 21:59:16 -0000 1.70
+++ malloc.c 9 Aug 2002 07:12:53 -0000
@@ -1093,6 +1093,7 @@
wrtwarning("recursive call\n");
malloc_active--;
THREAD_UNLOCK();
+ errno = EPERM;
return (0);
}
if (!malloc_started)
@@ -1108,6 +1109,8 @@
THREAD_UNLOCK();
if (malloc_xmalloc && !r)
wrterror("out of memory\n");
+ if (!r)
+ errno = ENOMEM;
return (r);
}
@@ -1120,6 +1123,7 @@
wrtwarning("recursive call\n");
malloc_active--;
THREAD_UNLOCK();
+ errno = EPERM;
return;
}
if (ptr != ZEROSIZEPTR)
@@ -1142,6 +1146,7 @@
wrtwarning("recursive call\n");
malloc_active--;
THREAD_UNLOCK();
+ errno = EPERM;
return (0);
}
if (ptr && !malloc_started) {
@@ -1170,6 +1175,8 @@
THREAD_UNLOCK();
if (malloc_xmalloc && err)
wrterror("out of memory\n");
+ if (err)
+ errno = ENOMEM;
return (r);
}
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?10593.1028877062>
