aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/blf.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2023-05-19 00:53:36 -0700
committerGuy Harris <gharris@sonic.net>2023-05-19 00:54:43 -0700
commite6a2976af6fcc01b236b785e96d123bad9333821 (patch)
tree9797ac2f46a9691c802c3a02a8f43f2356aa193d /wiretap/blf.c
parentf10a66999bf10f76e1171c4d4c9e218592e6647b (diff)
blf: plug some leaks on read errors.
If we've allocated a buffer of compressed data or a buffer into which we're uncompressing that data, and we get an error, free those buffers. If we've allocated a buffer of compressed data, and we *don't* get an error reading or uncompressing that data, free it once we're finished uncompressing it.
Diffstat (limited to 'wiretap/blf.c')
-rw-r--r--wiretap/blf.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/wiretap/blf.c b/wiretap/blf.c
index cf2cec55bf..c528aba8d8 100644
--- a/wiretap/blf.c
+++ b/wiretap/blf.c
@@ -529,7 +529,6 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe
}
/* pull compressed data into buffer */
- unsigned char *compressed_data = g_try_malloc0((gsize)tmp.infile_length);
if (tmp.infile_start_pos < 0) {
/*
* XXX - does this represent a bug (WTAP_ERR_INTERNAL) or a
@@ -573,7 +572,9 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe
data_length);
return FALSE;
}
+ unsigned char *compressed_data = g_try_malloc0((gsize)tmp.infile_length);
if (!wtap_read_bytes_or_eof(params->fh, compressed_data, (unsigned int)data_length, err, err_info)) {
+ g_free(compressed_data);
if (*err == WTAP_ERR_SHORT_READ) {
/*
* XXX - our caller will turn this into an EOF.
@@ -601,6 +602,8 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe
/*
* XXX - check the error code and handle this appropriately.
*/
+ g_free(buf);
+ g_free(compressed_data);
*err = WTAP_ERR_INTERNAL;
if (infstream.msg != NULL) {
*err_info = ws_strdup_printf("blf_pull_logcontainer_into_memory: inflateInit failed for LogContainer %d, message\"%s\"",
@@ -664,6 +667,8 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe
(infstream.msg != NULL) ? infstream.msg : "(none)");
break;
}
+ g_free(buf);
+ g_free(compressed_data);
ws_debug("inflate failed (return code %d) for LogContainer %d", ret, index_log_container);
if (infstream.msg != NULL) {
ws_debug("inflate returned: \"%s\"", infstream.msg);
@@ -682,6 +687,7 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, guint index_log_containe
return FALSE;
}
+ g_free(compressed_data);
tmp.real_data = buf;
g_array_index(blf_data->log_containers, blf_log_container_t, index_log_container) = tmp;
return TRUE;