1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
From: Helmut Grohne <helmut@subdivi.de>
Date: Sat, 11 Nov 2023 18:18:40 +0100
Subject: hcom: fix dictionary resource leaks
startread and stopread should release p->dictionary in all failure modes.
---
src/hcom.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/hcom.c b/src/hcom.c
index be17d9d..75a2820 100644
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -160,13 +160,18 @@ static int startread(sox_format_t * ft)
p->dictionary[i].dict_rightson);
if (!dictvalid(i, dictsize, p->dictionary[i].dict_leftson,
p->dictionary[i].dict_rightson)) {
+ free(p->dictionary);
+ p->dictionary = NULL;
lsx_fail_errno(ft, SOX_EHDR, "Invalid dictionary");
return SOX_EOF;
}
}
rc = lsx_skipbytes(ft, (size_t) 1); /* skip pad byte */
- if (rc)
+ if (rc) {
+ free(p->dictionary);
+ p->dictionary = NULL;
return rc;
+ }
/* Initialized the decompression engine */
p->checksum = checksum;
@@ -248,6 +253,8 @@ static int stopread(sox_format_t * ft)
{
register priv_t *p = (priv_t *) ft->priv;
+ free(p->dictionary);
+ p->dictionary = NULL;
if (p->huffcount != 0)
{
lsx_fail_errno(ft,SOX_EFMT,"not all HCOM data read");
@@ -258,8 +265,6 @@ static int stopread(sox_format_t * ft)
lsx_fail_errno(ft,SOX_EFMT,"checksum error in HCOM data");
return (SOX_EOF);
}
- free(p->dictionary);
- p->dictionary = NULL;
return (SOX_SUCCESS);
}
|