diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-01 19:59:37 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-01 19:59:37 +0200 |
commit | 899ae5337acc2d24edcd64e570adfc5f3c1a8a8a (patch) | |
tree | 9ec3de6ffce8df5f82d1428d595ffe4028905a3d | |
parent | e2afae6303e871a31a061d03359cfcd5dd86c088 (diff) | |
download | busybox-w32-899ae5337acc2d24edcd64e570adfc5f3c1a8a8a.tar.gz busybox-w32-899ae5337acc2d24edcd64e570adfc5f3c1a8a8a.tar.bz2 busybox-w32-899ae5337acc2d24edcd64e570adfc5f3c1a8a8a.zip |
libbb: new function bb_die_memory_exhausted
function old new delta
bb_die_memory_exhausted - 10 +10
xstrdup 28 23 -5
xsetenv 27 22 -5
xrealloc 32 27 -5
xputenv 22 17 -5
xmalloc 30 25 -5
xfdopen_helper 40 35 -5
xasprintf 44 39 -5
wget_main 2387 2382 -5
open_socket 54 49 -5
glob_brace 419 414 -5
bb_get_chunk_from_file 146 141 -5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/11 up/down: 10/-55) Total: -45 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/libarchive/data_extract_to_command.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 29 | ||||
-rw-r--r-- | libbb/get_line_from_file.c | 2 | ||||
-rw-r--r-- | libbb/wfopen.c | 2 | ||||
-rw-r--r-- | libbb/xfuncs_printf.c | 15 | ||||
-rw-r--r-- | networking/wget.c | 4 | ||||
-rw-r--r-- | shell/hush.c | 4 |
7 files changed, 32 insertions, 26 deletions
diff --git a/archival/libarchive/data_extract_to_command.c b/archival/libarchive/data_extract_to_command.c index 1114a95cb..0fcabb4a9 100644 --- a/archival/libarchive/data_extract_to_command.c +++ b/archival/libarchive/data_extract_to_command.c | |||
@@ -37,7 +37,7 @@ static const char *const tar_var[] = { | |||
37 | static void xputenv(char *str) | 37 | static void xputenv(char *str) |
38 | { | 38 | { |
39 | if (putenv(str)) | 39 | if (putenv(str)) |
40 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 40 | bb_die_memory_exhausted(); |
41 | } | 41 | } |
42 | 42 | ||
43 | static void str2env(char *env[], int idx, const char *str) | 43 | static void str2env(char *env[], int idx, const char *str) |
diff --git a/include/libbb.h b/include/libbb.h index 309c58734..ad1c7346f 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1277,20 +1277,21 @@ extern smallint syslog_level; | |||
1277 | extern smallint logmode; | 1277 | extern smallint logmode; |
1278 | extern uint8_t xfunc_error_retval; | 1278 | extern uint8_t xfunc_error_retval; |
1279 | extern void (*die_func)(void); | 1279 | extern void (*die_func)(void); |
1280 | extern void xfunc_die(void) NORETURN FAST_FUNC; | 1280 | void xfunc_die(void) NORETURN FAST_FUNC; |
1281 | extern void bb_show_usage(void) NORETURN FAST_FUNC; | 1281 | void bb_show_usage(void) NORETURN FAST_FUNC; |
1282 | extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1282 | void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; |
1283 | extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1283 | void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; |
1284 | extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1284 | void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; |
1285 | extern void bb_simple_perror_msg(const char *s) FAST_FUNC; | 1285 | void bb_simple_perror_msg(const char *s) FAST_FUNC; |
1286 | extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1286 | void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; |
1287 | extern void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC; | 1287 | void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC; |
1288 | extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1288 | void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; |
1289 | extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1289 | void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; |
1290 | extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; | 1290 | void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; |
1291 | extern void bb_perror_nomsg(void) FAST_FUNC; | 1291 | void bb_perror_nomsg(void) FAST_FUNC; |
1292 | extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC; | 1292 | void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC; |
1293 | extern void bb_logenv_override(void) FAST_FUNC; | 1293 | void bb_die_memory_exhausted(void) NORETURN FAST_FUNC; |
1294 | void bb_logenv_override(void) FAST_FUNC; | ||
1294 | 1295 | ||
1295 | /* We need to export XXX_main from libbusybox | 1296 | /* We need to export XXX_main from libbusybox |
1296 | * only if we build "individual" binaries | 1297 | * only if we build "individual" binaries |
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c index d10066937..f3d6c6203 100644 --- a/libbb/get_line_from_file.c +++ b/libbb/get_line_from_file.c | |||
@@ -20,7 +20,7 @@ char* FAST_FUNC bb_get_chunk_from_file(FILE *file, size_t *end) | |||
20 | /* grow the line buffer as necessary */ | 20 | /* grow the line buffer as necessary */ |
21 | if (!(idx & 0xff)) { | 21 | if (!(idx & 0xff)) { |
22 | if (idx == ((size_t)-1) - 0xff) | 22 | if (idx == ((size_t)-1) - 0xff) |
23 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 23 | bb_die_memory_exhausted(); |
24 | linebuf = xrealloc(linebuf, idx + 0x100); | 24 | linebuf = xrealloc(linebuf, idx + 0x100); |
25 | } | 25 | } |
26 | linebuf[idx++] = (char) ch; | 26 | linebuf[idx++] = (char) ch; |
diff --git a/libbb/wfopen.c b/libbb/wfopen.c index 20fe18b23..1c7f7f3d7 100644 --- a/libbb/wfopen.c +++ b/libbb/wfopen.c | |||
@@ -42,7 +42,7 @@ static FILE* xfdopen_helper(unsigned fd_and_rw_bit) | |||
42 | { | 42 | { |
43 | FILE* fp = fdopen(fd_and_rw_bit >> 1, fd_and_rw_bit & 1 ? "w" : "r"); | 43 | FILE* fp = fdopen(fd_and_rw_bit >> 1, fd_and_rw_bit & 1 ? "w" : "r"); |
44 | if (!fp) | 44 | if (!fp) |
45 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 45 | bb_die_memory_exhausted(); |
46 | return fp; | 46 | return fp; |
47 | } | 47 | } |
48 | FILE* FAST_FUNC xfdopen_for_read(int fd) | 48 | FILE* FAST_FUNC xfdopen_for_read(int fd) |
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 2bc01ad10..7247c915b 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c | |||
@@ -25,6 +25,11 @@ | |||
25 | * fail, so callers never need to check for errors. If it returned, it | 25 | * fail, so callers never need to check for errors. If it returned, it |
26 | * succeeded. */ | 26 | * succeeded. */ |
27 | 27 | ||
28 | void FAST_FUNC bb_die_memory_exhausted(void) | ||
29 | { | ||
30 | bb_error_msg_and_die(bb_msg_memory_exhausted); | ||
31 | } | ||
32 | |||
28 | #ifndef DMALLOC | 33 | #ifndef DMALLOC |
29 | /* dmalloc provides variants of these that do abort() on failure. | 34 | /* dmalloc provides variants of these that do abort() on failure. |
30 | * Since dmalloc's prototypes overwrite the impls here as they are | 35 | * Since dmalloc's prototypes overwrite the impls here as they are |
@@ -44,7 +49,7 @@ void* FAST_FUNC xmalloc(size_t size) | |||
44 | { | 49 | { |
45 | void *ptr = malloc(size); | 50 | void *ptr = malloc(size); |
46 | if (ptr == NULL && size != 0) | 51 | if (ptr == NULL && size != 0) |
47 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 52 | bb_die_memory_exhausted(); |
48 | return ptr; | 53 | return ptr; |
49 | } | 54 | } |
50 | 55 | ||
@@ -55,7 +60,7 @@ void* FAST_FUNC xrealloc(void *ptr, size_t size) | |||
55 | { | 60 | { |
56 | ptr = realloc(ptr, size); | 61 | ptr = realloc(ptr, size); |
57 | if (ptr == NULL && size != 0) | 62 | if (ptr == NULL && size != 0) |
58 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 63 | bb_die_memory_exhausted(); |
59 | return ptr; | 64 | return ptr; |
60 | } | 65 | } |
61 | #endif /* DMALLOC */ | 66 | #endif /* DMALLOC */ |
@@ -79,7 +84,7 @@ char* FAST_FUNC xstrdup(const char *s) | |||
79 | t = strdup(s); | 84 | t = strdup(s); |
80 | 85 | ||
81 | if (t == NULL) | 86 | if (t == NULL) |
82 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 87 | bb_die_memory_exhausted(); |
83 | 88 | ||
84 | return t; | 89 | return t; |
85 | } | 90 | } |
@@ -327,14 +332,14 @@ char* FAST_FUNC xasprintf(const char *format, ...) | |||
327 | va_end(p); | 332 | va_end(p); |
328 | 333 | ||
329 | if (r < 0) | 334 | if (r < 0) |
330 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 335 | bb_die_memory_exhausted(); |
331 | return string_ptr; | 336 | return string_ptr; |
332 | } | 337 | } |
333 | 338 | ||
334 | void FAST_FUNC xsetenv(const char *key, const char *value) | 339 | void FAST_FUNC xsetenv(const char *key, const char *value) |
335 | { | 340 | { |
336 | if (setenv(key, value, 1)) | 341 | if (setenv(key, value, 1)) |
337 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 342 | bb_die_memory_exhausted(); |
338 | } | 343 | } |
339 | 344 | ||
340 | /* Handles "VAR=VAL" strings, even those which are part of environ | 345 | /* Handles "VAR=VAL" strings, even those which are part of environ |
diff --git a/networking/wget.c b/networking/wget.c index 8969310a4..12ee29a6f 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -409,7 +409,7 @@ static FILE *open_socket(len_and_sockaddr *lsa) | |||
409 | /* hopefully it understands what ESPIPE means... */ | 409 | /* hopefully it understands what ESPIPE means... */ |
410 | fp = fdopen(fd, "r+"); | 410 | fp = fdopen(fd, "r+"); |
411 | if (!fp) | 411 | if (!fp) |
412 | bb_perror_msg_and_die(bb_msg_memory_exhausted); | 412 | bb_die_memory_exhausted(); |
413 | 413 | ||
414 | return fp; | 414 | return fp; |
415 | } | 415 | } |
@@ -1114,7 +1114,7 @@ static void download_one_url(const char *url) | |||
1114 | # endif | 1114 | # endif |
1115 | sfp = fdopen(fd, "r+"); | 1115 | sfp = fdopen(fd, "r+"); |
1116 | if (!sfp) | 1116 | if (!sfp) |
1117 | bb_perror_msg_and_die(bb_msg_memory_exhausted); | 1117 | bb_die_memory_exhausted(); |
1118 | goto socket_opened; | 1118 | goto socket_opened; |
1119 | } | 1119 | } |
1120 | sfp = open_socket(lsa); | 1120 | sfp = open_socket(lsa); |
diff --git a/shell/hush.c b/shell/hush.c index 1921932d1..8246b5fd8 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -3158,7 +3158,7 @@ static int glob_brace(char *pattern, o_string *o, int n) | |||
3158 | return o_save_ptr_helper(o, n); | 3158 | return o_save_ptr_helper(o, n); |
3159 | } | 3159 | } |
3160 | if (gr == GLOB_NOSPACE) | 3160 | if (gr == GLOB_NOSPACE) |
3161 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 3161 | bb_die_memory_exhausted(); |
3162 | /* GLOB_ABORTED? Only happens with GLOB_ERR flag, | 3162 | /* GLOB_ABORTED? Only happens with GLOB_ERR flag, |
3163 | * but we didn't specify it. Paranoia again. */ | 3163 | * but we didn't specify it. Paranoia again. */ |
3164 | bb_error_msg_and_die("glob error %d on '%s'", gr, pattern); | 3164 | bb_error_msg_and_die("glob error %d on '%s'", gr, pattern); |
@@ -3260,7 +3260,7 @@ static int perform_glob(o_string *o, int n) | |||
3260 | goto literal; | 3260 | goto literal; |
3261 | } | 3261 | } |
3262 | if (gr == GLOB_NOSPACE) | 3262 | if (gr == GLOB_NOSPACE) |
3263 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 3263 | bb_die_memory_exhausted(); |
3264 | /* GLOB_ABORTED? Only happens with GLOB_ERR flag, | 3264 | /* GLOB_ABORTED? Only happens with GLOB_ERR flag, |
3265 | * but we didn't specify it. Paranoia again. */ | 3265 | * but we didn't specify it. Paranoia again. */ |
3266 | bb_error_msg_and_die("glob error %d on '%s'", gr, pattern); | 3266 | bb_error_msg_and_die("glob error %d on '%s'", gr, pattern); |