aboutsummaryrefslogtreecommitdiffstats
path: root/erts/lib_src
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2013-02-13 14:18:36 +0100
committerLukas Larsson <[email protected]>2013-02-13 14:18:36 +0100
commite55aff9434072dc9ba45b610d2e5110b0d537692 (patch)
tree621ad19e00799bd3e7bc7501f715918d3743fedc /erts/lib_src
parentcd08400f92ec7672025bf39a458effcf33a423dc (diff)
parent4326a0b5030c46a679de0c39dba547783f1dc0e9 (diff)
downloadotp-e55aff9434072dc9ba45b610d2e5110b0d537692.tar.gz
otp-e55aff9434072dc9ba45b610d2e5110b0d537692.tar.bz2
otp-e55aff9434072dc9ba45b610d2e5110b0d537692.zip
Merge branch 'saleyn/float_to_list_2/OTP-10837'
* saleyn/float_to_list_2/OTP-10837: Fix memory leak in error case Use macros instead of constants float_to_list/2 changed rounding and cosmetic cleanup
Diffstat (limited to 'erts/lib_src')
-rw-r--r--erts/lib_src/common/erl_printf_format.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/erts/lib_src/common/erl_printf_format.c b/erts/lib_src/common/erl_printf_format.c
index 384b1b1ad7..00df3f068f 100644
--- a/erts/lib_src/common/erl_printf_format.c
+++ b/erts/lib_src/common/erl_printf_format.c
@@ -335,7 +335,7 @@ static int fmt_double(fmtfn_t fn,void*arg,double val,
int fi = 0;
char format_str[7];
char sbuf[32];
- char *bufp;
+ char *bufp = sbuf;
double dexp;
int exp;
size_t max_size = 1;
@@ -425,12 +425,12 @@ static int fmt_double(fmtfn_t fn,void*arg,double val,
max_size++; /* '\0' */
- if (max_size < sizeof(sbuf))
- bufp = sbuf;
- else {
+ if (max_size >= sizeof(sbuf)) {
bufp = (char *) malloc(sizeof(char)*max_size);
if (!bufp) {
res = -ENOMEM;
+ /* Make sure not to trigger free */
+ bufp = sbuf;
goto out;
}
}
@@ -448,10 +448,10 @@ static int fmt_double(fmtfn_t fn,void*arg,double val,
res = fmt_fld(fn, arg, bufp, size, 0, width, 0, new_fmt, count);
+ out:
if (bufp != sbuf)
free((void *) bufp);
- out:
if (erts_printf_unblock_fpe)
(*erts_printf_unblock_fpe)(fpe_was_unmasked);
return res;