aboutsummaryrefslogtreecommitdiffstats
path: root/erts/lib_src
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2013-02-12 10:09:46 +0100
committerLukas Larsson <[email protected]>2013-02-13 14:10:16 +0100
commit4326a0b5030c46a679de0c39dba547783f1dc0e9 (patch)
tree2e02345c84d88bb5ec5c84bd70c0f3d93fffcf73 /erts/lib_src
parentfc8ed627b5dc77cc294fcd207378cf803ba3f3dd (diff)
downloadotp-4326a0b5030c46a679de0c39dba547783f1dc0e9.tar.gz
otp-4326a0b5030c46a679de0c39dba547783f1dc0e9.tar.bz2
otp-4326a0b5030c46a679de0c39dba547783f1dc0e9.zip
Fix memory leak in error case
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;