summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPatrick Georgi <patrick@georgi-clan.de>2014-08-09 17:06:20 +0200
committerPatrick Georgi <patrick@georgi-clan.de>2014-08-12 22:15:20 +0200
commitdd1aab95a6eb74eac7ea0463f7933d186dbd0efb (patch)
treeb5c709f80ae610cf493e3284f57c273de7478ade /util
parent42b1b8069c35a4e86772b600ea0264503bf20470 (diff)
downloadcoreboot-dd1aab95a6eb74eac7ea0463f7933d186dbd0efb.tar.xz
nvramtool: plug some memory leaks
Change-Id: I8f672b872862d3448ccd2cf28fd3c05b0108ff8b Found-by: Coverity Scan Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-on: http://review.coreboot.org/6561 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/nvramtool/cmos_lowlevel.c5
-rw-r--r--util/nvramtool/cmos_ops.c6
2 files changed, 8 insertions, 3 deletions
diff --git a/util/nvramtool/cmos_lowlevel.c b/util/nvramtool/cmos_lowlevel.c
index ef0c3832b1..618e8d2b27 100644
--- a/util/nvramtool/cmos_lowlevel.c
+++ b/util/nvramtool/cmos_lowlevel.c
@@ -125,13 +125,16 @@ unsigned long long cmos_read(const cmos_entry_t * e)
result = 0;
if (e->config == CMOS_ENTRY_STRING) {
- char *newstring = calloc(1, (length + 7) / 8);
+ int strsz = (length + 7) / 8;
+ char *newstring = alloca(strsz);
unsigned usize = (8 * sizeof(unsigned long long));
if (!newstring) {
out_of_memory();
}
+ memset(newstring, 0, strsz);
+
for (next_bit = 0, bits_left = length;
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
nr_bits = cmos_bit_op_strategy(bit + next_bit,
diff --git a/util/nvramtool/cmos_ops.c b/util/nvramtool/cmos_ops.c
index 91c9f451ac..cb6c37931d 100644
--- a/util/nvramtool/cmos_ops.c
+++ b/util/nvramtool/cmos_ops.c
@@ -95,7 +95,7 @@ int prepare_cmos_write(const cmos_entry_t * e, const char value_str[],
const cmos_enum_t *q;
unsigned long long out;
const char *p;
- char *memory;
+ char *memory = NULL;
int negative, result, found_one;
if ((result = prepare_cmos_op_common(e)) != OK)
@@ -155,8 +155,10 @@ int prepare_cmos_write(const cmos_entry_t * e, const char value_str[],
BUG();
}
- if ((e->length < (8 * sizeof(*value))) && (out >= (1ull << e->length)))
+ if ((e->length < (8 * sizeof(*value))) && (out >= (1ull << e->length))) {
+ if (memory) free(memory);
return CMOS_OP_VALUE_TOO_WIDE;
+ }
*value = out;
return OK;