diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 689fa8996a..5a67042333 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #if defined(LIBC_SCCS) && !defined(lint) | 10 | #if defined(LIBC_SCCS) && !defined(lint) |
| 11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.64 2003/10/16 17:05:05 tedu Exp $"; | 11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.65 2003/11/19 02:27:18 tedu Exp $"; |
| 12 | #endif /* LIBC_SCCS and not lint */ | 12 | #endif /* LIBC_SCCS and not lint */ |
| 13 | 13 | ||
| 14 | /* | 14 | /* |
| @@ -992,11 +992,10 @@ irealloc(void *ptr, size_t size) | |||
| 992 | */ | 992 | */ |
| 993 | 993 | ||
| 994 | static __inline__ void | 994 | static __inline__ void |
| 995 | free_pages(void *ptr, int index, struct pginfo *info) | 995 | free_pages(void *ptr, u_long index, struct pginfo *info) |
| 996 | { | 996 | { |
| 997 | int i; | 997 | u_long i, l; |
| 998 | struct pgfree *pf, *pt=NULL; | 998 | struct pgfree *pf, *pt=NULL; |
| 999 | u_long l; | ||
| 1000 | void *tail; | 999 | void *tail; |
| 1001 | 1000 | ||
| 1002 | if (info == MALLOC_FREE) { | 1001 | if (info == MALLOC_FREE) { |
| @@ -1205,7 +1204,7 @@ static void | |||
| 1205 | ifree(void *ptr) | 1204 | ifree(void *ptr) |
| 1206 | { | 1205 | { |
| 1207 | struct pginfo *info; | 1206 | struct pginfo *info; |
| 1208 | int index; | 1207 | u_long index; |
| 1209 | 1208 | ||
| 1210 | /* This is legal */ | 1209 | /* This is legal */ |
| 1211 | if (ptr == NULL) | 1210 | if (ptr == NULL) |
| @@ -1241,12 +1240,29 @@ ifree(void *ptr) | |||
| 1241 | return; | 1240 | return; |
| 1242 | } | 1241 | } |
| 1243 | 1242 | ||
| 1243 | static int malloc_active; | ||
| 1244 | |||
| 1244 | /* | 1245 | /* |
| 1245 | * These are the public exported interface routines. | 1246 | * Common function for handling recursion. Only |
| 1247 | * print the error message once, to avoid making the problem | ||
| 1248 | * potentially worse. | ||
| 1246 | */ | 1249 | */ |
| 1250 | static void | ||
| 1251 | malloc_recurse(void) | ||
| 1252 | { | ||
| 1253 | static int noprint; | ||
| 1247 | 1254 | ||
| 1248 | static int malloc_active; | 1255 | if (noprint == 0) |
| 1256 | wrtwarning("recursive call\n"); | ||
| 1257 | noprint = 1; | ||
| 1258 | malloc_active--; | ||
| 1259 | _MALLOC_UNLOCK(); | ||
| 1260 | errno = EDEADLK; | ||
| 1261 | } | ||
| 1249 | 1262 | ||
| 1263 | /* | ||
| 1264 | * These are the public exported interface routines. | ||
| 1265 | */ | ||
| 1250 | void * | 1266 | void * |
| 1251 | malloc(size_t size) | 1267 | malloc(size_t size) |
| 1252 | { | 1268 | { |
| @@ -1255,10 +1271,7 @@ malloc(size_t size) | |||
| 1255 | _MALLOC_LOCK(); | 1271 | _MALLOC_LOCK(); |
| 1256 | malloc_func = " in malloc():"; | 1272 | malloc_func = " in malloc():"; |
| 1257 | if (malloc_active++) { | 1273 | if (malloc_active++) { |
| 1258 | wrtwarning("recursive call\n"); | 1274 | malloc_recurse(); |
| 1259 | malloc_active--; | ||
| 1260 | _MALLOC_UNLOCK(); | ||
| 1261 | errno = EDEADLK; | ||
| 1262 | return (NULL); | 1275 | return (NULL); |
| 1263 | } | 1276 | } |
| 1264 | r = imalloc(size); | 1277 | r = imalloc(size); |
| @@ -1276,10 +1289,7 @@ free(void *ptr) | |||
| 1276 | _MALLOC_LOCK(); | 1289 | _MALLOC_LOCK(); |
| 1277 | malloc_func = " in free():"; | 1290 | malloc_func = " in free():"; |
| 1278 | if (malloc_active++) { | 1291 | if (malloc_active++) { |
| 1279 | wrtwarning("recursive call\n"); | 1292 | malloc_recurse(); |
| 1280 | malloc_active--; | ||
| 1281 | _MALLOC_UNLOCK(); | ||
| 1282 | errno = EDEADLK; | ||
| 1283 | return; | 1293 | return; |
| 1284 | } | 1294 | } |
| 1285 | ifree(ptr); | 1295 | ifree(ptr); |
| @@ -1297,10 +1307,7 @@ realloc(void *ptr, size_t size) | |||
| 1297 | _MALLOC_LOCK(); | 1307 | _MALLOC_LOCK(); |
| 1298 | malloc_func = " in realloc():"; | 1308 | malloc_func = " in realloc():"; |
| 1299 | if (malloc_active++) { | 1309 | if (malloc_active++) { |
| 1300 | wrtwarning("recursive call\n"); | 1310 | malloc_recurse(); |
| 1301 | malloc_active--; | ||
| 1302 | _MALLOC_UNLOCK(); | ||
| 1303 | errno = EDEADLK; | ||
| 1304 | return (NULL); | 1311 | return (NULL); |
| 1305 | } | 1312 | } |
| 1306 | if (ptr == NULL) { | 1313 | if (ptr == NULL) { |
