diff options
| author | Masaki Muranaka <[email protected]> | 2013-04-25 16:37:06 +0900 |
|---|---|---|
| committer | Masaki Muranaka <[email protected]> | 2013-04-25 16:38:31 +0900 |
| commit | 9479e4e28764b86bce88c7d9756c276b395faea9 (patch) | |
| tree | af3bbde0589008388f0b664646293422a4c8a661 /src | |
| parent | 8464cac63cce822245f76284a48d35343b680507 (diff) | |
| download | mruby-9479e4e28764b86bce88c7d9756c276b395faea9.tar.gz mruby-9479e4e28764b86bce88c7d9756c276b395faea9.zip | |
Fix underlying memory leaks. When realloc is failed, memories are leaked.
Diffstat (limited to 'src')
| -rw-r--r-- | src/load.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/load.c b/src/load.c index 213d8f899..5dee7021b 100644 --- a/src/load.c +++ b/src/load.c @@ -389,12 +389,19 @@ read_rite_section_lineno_file(mrb_state *mrb, FILE *fp, size_t sirep) //Read Binary Data Section for (n = 0, i = sirep; n < nirep; n++, i++) { + void *ptr; + if (fread(buf, record_header_size, 1, fp) == 0) { result = MRB_DUMP_READ_FAULT; goto error_exit; } buf_size = bin_to_uint32(&buf[0]); - buf = (uint8_t *)mrb_realloc(mrb, buf, buf_size); + ptr = mrb_realloc(mrb, buf, buf_size); + if (!ptr) { + result = MRB_DUMP_GENERAL_FAILURE; + goto error_exit; + } + buf = (uint8_t *)ptr; if (fread(&buf[record_header_size], buf_size - record_header_size, 1, fp) == 0) { result = MRB_DUMP_READ_FAULT; @@ -439,12 +446,20 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp) //Read Binary Data Section for (n = 0, i = sirep; n < nirep; n++, i++) { + void *ptr; + if (fread(buf, record_header_size, 1, fp) == 0) { result = MRB_DUMP_READ_FAULT; goto error_exit; } buf_size = bin_to_uint32(&buf[0]); - buf = (uint8_t *)mrb_realloc(mrb, buf, buf_size); + ptr = mrb_realloc(mrb, buf, buf_size); + if (!ptr) { + result = MRB_DUMP_GENERAL_FAILURE; + goto error_exit; + } + buf = (uint8_t *)ptr; + if (fread(&buf[record_header_size], buf_size - record_header_size, 1, fp) == 0) { result = MRB_DUMP_READ_FAULT; goto error_exit; |
