diff options
Diffstat (limited to 'src/lib/libc/stdlib/malloc.c')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.c | 50 |
1 files changed, 15 insertions, 35 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index c4869527ad..a4a4e52bda 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: malloc.c,v 1.89 2008/04/13 00:22:16 djm Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.90 2008/05/19 19:36:15 otto Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * ---------------------------------------------------------------------------- | 4 | * ---------------------------------------------------------------------------- |
| @@ -250,9 +250,9 @@ static char *malloc_func; | |||
| 250 | /* | 250 | /* |
| 251 | * Necessary function declarations. | 251 | * Necessary function declarations. |
| 252 | */ | 252 | */ |
| 253 | static void *imalloc(size_t size, int zero_fill); | 253 | static void *imalloc(size_t size); |
| 254 | static void ifree(void *ptr); | 254 | static void ifree(void *ptr); |
| 255 | static void *irealloc(void *ptr, size_t size, int zero_fill); | 255 | static void *irealloc(void *ptr, size_t size); |
| 256 | static void *malloc_bytes(size_t size); | 256 | static void *malloc_bytes(size_t size); |
| 257 | 257 | ||
| 258 | static struct pginfo *pginfo_list; | 258 | static struct pginfo *pginfo_list; |
| @@ -1188,7 +1188,7 @@ malloc_bytes(size_t size) | |||
| 1188 | * Allocate a piece of memory | 1188 | * Allocate a piece of memory |
| 1189 | */ | 1189 | */ |
| 1190 | static void * | 1190 | static void * |
| 1191 | imalloc(size_t size, int zero_fill) | 1191 | imalloc(size_t size) |
| 1192 | { | 1192 | { |
| 1193 | void *result; | 1193 | void *result; |
| 1194 | int ptralloc = 0; | 1194 | int ptralloc = 0; |
| @@ -1218,7 +1218,7 @@ imalloc(size_t size, int zero_fill) | |||
| 1218 | if (malloc_abort == 1 && result == NULL) | 1218 | if (malloc_abort == 1 && result == NULL) |
| 1219 | wrterror("allocation failed"); | 1219 | wrterror("allocation failed"); |
| 1220 | 1220 | ||
| 1221 | if ((malloc_zero || zero_fill) && result != NULL) | 1221 | if (malloc_zero && result != NULL) |
| 1222 | memset(result, 0, size); | 1222 | memset(result, 0, size); |
| 1223 | 1223 | ||
| 1224 | if (result && ptralloc) | 1224 | if (result && ptralloc) |
| @@ -1230,7 +1230,7 @@ imalloc(size_t size, int zero_fill) | |||
| 1230 | * Change the size of an allocation. | 1230 | * Change the size of an allocation. |
| 1231 | */ | 1231 | */ |
| 1232 | static void * | 1232 | static void * |
| 1233 | irealloc(void *ptr, size_t size, int zero_fill) | 1233 | irealloc(void *ptr, size_t size) |
| 1234 | { | 1234 | { |
| 1235 | void *p; | 1235 | void *p; |
| 1236 | size_t osize; | 1236 | size_t osize; |
| @@ -1253,7 +1253,7 @@ irealloc(void *ptr, size_t size, int zero_fill) | |||
| 1253 | if (size <= PTR_SIZE) | 1253 | if (size <= PTR_SIZE) |
| 1254 | return (ptr); | 1254 | return (ptr); |
| 1255 | 1255 | ||
| 1256 | p = imalloc(size, zero_fill); | 1256 | p = imalloc(size); |
| 1257 | if (p) | 1257 | if (p) |
| 1258 | memcpy(p, ptr, PTR_SIZE); | 1258 | memcpy(p, ptr, PTR_SIZE); |
| 1259 | ifree(ptr); | 1259 | ifree(ptr); |
| @@ -1315,9 +1315,7 @@ irealloc(void *ptr, size_t size, int zero_fill) | |||
| 1315 | 1315 | ||
| 1316 | if (!malloc_realloc && size <= osize && | 1316 | if (!malloc_realloc && size <= osize && |
| 1317 | size > osize - malloc_pagesize) { | 1317 | size > osize - malloc_pagesize) { |
| 1318 | if (zero_fill) | 1318 | if (malloc_junk) |
| 1319 | memset((char *)ptr + size, 0, osize - size); | ||
| 1320 | else if (malloc_junk) | ||
| 1321 | memset((char *)ptr + size, SOME_JUNK, osize - size); | 1319 | memset((char *)ptr + size, SOME_JUNK, osize - size); |
| 1322 | return (ptr); /* ..don't do anything else. */ | 1320 | return (ptr); /* ..don't do anything else. */ |
| 1323 | } | 1321 | } |
| @@ -1340,9 +1338,7 @@ irealloc(void *ptr, size_t size, int zero_fill) | |||
| 1340 | 1338 | ||
| 1341 | if (!malloc_realloc && size <= osize && | 1339 | if (!malloc_realloc && size <= osize && |
| 1342 | (size > osize / 2 || osize == malloc_minsize)) { | 1340 | (size > osize / 2 || osize == malloc_minsize)) { |
| 1343 | if (zero_fill) | 1341 | if (malloc_junk) |
| 1344 | memset((char *) ptr + size, 0, osize - size); | ||
| 1345 | else if (malloc_junk) | ||
| 1346 | memset((char *) ptr + size, SOME_JUNK, osize - size); | 1342 | memset((char *) ptr + size, SOME_JUNK, osize - size); |
| 1347 | return (ptr); /* ..don't do anything else. */ | 1343 | return (ptr); /* ..don't do anything else. */ |
| 1348 | } | 1344 | } |
| @@ -1351,7 +1347,7 @@ irealloc(void *ptr, size_t size, int zero_fill) | |||
| 1351 | return (NULL); | 1347 | return (NULL); |
| 1352 | } | 1348 | } |
| 1353 | 1349 | ||
| 1354 | p = imalloc(size, zero_fill); | 1350 | p = imalloc(size); |
| 1355 | 1351 | ||
| 1356 | if (p != NULL) { | 1352 | if (p != NULL) { |
| 1357 | /* copy the lesser of the two sizes, and free the old one */ | 1353 | /* copy the lesser of the two sizes, and free the old one */ |
| @@ -1880,7 +1876,7 @@ malloc(size_t size) | |||
| 1880 | malloc_recurse(); | 1876 | malloc_recurse(); |
| 1881 | return (NULL); | 1877 | return (NULL); |
| 1882 | } | 1878 | } |
| 1883 | r = imalloc(size, 0); | 1879 | r = imalloc(size); |
| 1884 | UTRACE(0, size, r); | 1880 | UTRACE(0, size, r); |
| 1885 | malloc_active--; | 1881 | malloc_active--; |
| 1886 | _MALLOC_UNLOCK(); | 1882 | _MALLOC_UNLOCK(); |
| @@ -1911,8 +1907,8 @@ free(void *ptr) | |||
| 1911 | return; | 1907 | return; |
| 1912 | } | 1908 | } |
| 1913 | 1909 | ||
| 1914 | static void * | 1910 | void * |
| 1915 | _realloc(void *ptr, size_t size, int zero_fill) | 1911 | realloc(void *ptr, size_t size) |
| 1916 | { | 1912 | { |
| 1917 | void *r; | 1913 | void *r; |
| 1918 | 1914 | ||
| @@ -1924,9 +1920,9 @@ _realloc(void *ptr, size_t size, int zero_fill) | |||
| 1924 | } | 1920 | } |
| 1925 | 1921 | ||
| 1926 | if (ptr == NULL) | 1922 | if (ptr == NULL) |
| 1927 | r = imalloc(size, zero_fill); | 1923 | r = imalloc(size); |
| 1928 | else | 1924 | else |
| 1929 | r = irealloc(ptr, size, zero_fill); | 1925 | r = irealloc(ptr, size); |
| 1930 | 1926 | ||
| 1931 | UTRACE(ptr, size, r); | 1927 | UTRACE(ptr, size, r); |
| 1932 | malloc_active--; | 1928 | malloc_active--; |
| @@ -1937,19 +1933,3 @@ _realloc(void *ptr, size_t size, int zero_fill) | |||
| 1937 | } | 1933 | } |
| 1938 | return (r); | 1934 | return (r); |
| 1939 | } | 1935 | } |
| 1940 | |||
| 1941 | void * | ||
| 1942 | realloc(void *ptr, size_t size) | ||
| 1943 | { | ||
| 1944 | return (_realloc(ptr, size, 0)); | ||
| 1945 | } | ||
| 1946 | |||
| 1947 | void * | ||
| 1948 | recalloc(void *ptr, size_t nmemb, size_t size) | ||
| 1949 | { | ||
| 1950 | if (nmemb && SIZE_MAX / nmemb < size) { | ||
| 1951 | errno = ENOMEM; | ||
| 1952 | return (NULL); | ||
| 1953 | } | ||
| 1954 | return (_realloc(ptr, nmemb * size, 1)); | ||
| 1955 | } | ||
