diff options
author | Michael Santos <[email protected]> | 2016-01-28 11:11:45 -0500 |
---|---|---|
committer | Michael Santos <[email protected]> | 2016-01-28 11:11:45 -0500 |
commit | 9194e3beb7170c7a3db7391f005e6ab0aabd180d (patch) | |
tree | eda8de104e0e2f1a1e21555f8525600fcf8d57b5 /erts/etc/common/escript.c | |
parent | ff58636f3261150aec21c2209492c0a7feb75bd6 (diff) | |
download | otp-9194e3beb7170c7a3db7391f005e6ab0aabd180d.tar.gz otp-9194e3beb7170c7a3db7391f005e6ab0aabd180d.tar.bz2 otp-9194e3beb7170c7a3db7391f005e6ab0aabd180d.zip |
erts/common: check for OOM on Windows
Fix the command line tools to abort on allocation failures when run
on Windows. Modify the malloc() wrapper to consistently return void*
across all the tools.
Diffstat (limited to 'erts/etc/common/escript.c')
-rw-r--r-- | erts/etc/common/escript.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 7fd02ed436..ce53e77cee 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -71,7 +71,7 @@ static int eargc; /* Number of arguments in eargv. */ */ static void error(char* format, ...); -static char* emalloc(size_t size); +static void* emalloc(size_t size); static void efree(void *p); static char* strsave(char* string); static void push_words(char* src); @@ -79,6 +79,7 @@ static int run_erlang(char* name, char** argv); static char* get_default_emulator(char* progname); #ifdef __WIN32__ static char* possibly_quote(char* arg); +static void* erealloc(void *p, size_t size); #endif /* @@ -418,10 +419,10 @@ main(int argc, char** argv) int i; int len; /* Convert argv to utf8 */ - argv = malloc((argc+1) * sizeof(char*)); + argv = emalloc((argc+1) * sizeof(char*)); for (i=0; i<argc; i++) { len = WideCharToMultiByte(CP_UTF8, 0, wcargv[i], -1, NULL, 0, NULL, NULL); - argv[i] = malloc(len*sizeof(char)); + argv[i] = emalloc(len*sizeof(char)); WideCharToMultiByte(CP_UTF8, 0, wcargv[i], -1, argv[i], len, NULL, NULL); } argv[argc] = NULL; @@ -594,7 +595,7 @@ wchar_t *make_commandline(char **argv) buff = (wchar_t *) emalloc(siz*sizeof(wchar_t)); } else if (siz < num) { siz = num; - buff = (wchar_t *) realloc(buff,siz*sizeof(wchar_t)); + buff = (wchar_t *) erealloc(buff,siz*sizeof(wchar_t)); } p = buff; num=0; @@ -694,15 +695,26 @@ error(char* format, ...) exit(1); } -static char* +static void* emalloc(size_t size) { - char *p = malloc(size); + void *p = malloc(size); if (p == NULL) error("Insufficient memory"); return p; } +#ifdef __WIN32__ +static void * +erealloc(void *p, size_t size) +{ + void *res = realloc(p, size); + if (res == NULL) + error("Insufficient memory"); + return res; +} +#endif + static void efree(void *p) { |