diff options
author | Marc Schink <openocd-dev@marcschink.de> | 2015-10-02 17:12:17 +0200 |
---|---|---|
committer | Freddie Chopin <freddie.chopin@gmail.com> | 2015-11-03 22:15:31 +0000 |
commit | 627f1cb3542408533158dc5682b468ef48614eb8 (patch) | |
tree | 3508e482ecb82470bd48e47b519c9adc2b8c6628 /src/helper | |
parent | 24d9f0cfa0ee84e927d84957cab22c6571fa3185 (diff) | |
download | riscv-openocd-627f1cb3542408533158dc5682b468ef48614eb8.zip riscv-openocd-627f1cb3542408533158dc5682b468ef48614eb8.tar.gz riscv-openocd-627f1cb3542408533158dc5682b468ef48614eb8.tar.bz2 |
helper/fileio: Fix memory leak.
The memory leak occurs when opening a file fails. It can be
reproduced by using the "flash verify_bank" command with a filename
that does not exist.
Change-Id: I60b7b545c18793d750ff75d08124fde3f0aa6f64
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/2998
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src/helper')
-rw-r--r-- | src/helper/fileio.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/helper/fileio.c b/src/helper/fileio.c index 9d39313..2664bfa 100644 --- a/src/helper/fileio.c +++ b/src/helper/fileio.c @@ -109,10 +109,10 @@ int fileio_open(struct fileio *fileio_p, enum fileio_access access_type, enum fileio_type type) { - int retval = ERROR_OK; + int retval; + struct fileio_internal *fileio; - struct fileio_internal *fileio = malloc(sizeof(struct fileio_internal)); - fileio_p->fp = fileio; + fileio = malloc(sizeof(struct fileio_internal)); fileio->type = type; fileio->access = access_type; @@ -120,7 +120,15 @@ int fileio_open(struct fileio *fileio_p, retval = fileio_open_local(fileio); - return retval; + if (retval != ERROR_OK) { + free(fileio->url); + free(fileio); + return retval; + } + + fileio_p->fp = fileio; + + return ERROR_OK; } static inline int fileio_close_local(struct fileio_internal *fileio) |