checkAPIs.pl: support for new-style dissectors in check_hf_entries
[metze/wireshark/wip.git] / epan / tvbuff_zlib.c
index c1a6a1092cd40553f5e583ca1a123c761a0eeec0..0ed07ad4fdae8a6ce362c75f04826f09e45a4224 100644 (file)
@@ -6,19 +6,7 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include <config.h>
@@ -67,15 +55,14 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen)
        guint      bytes_in       = tvb_captured_length_remaining(tvb, offset);
 #endif
 
-       if (tvb == NULL) {
+       if (tvb == NULL || comprlen <= 0) {
                return NULL;
        }
 
-       compr = (guint8 *)g_malloc(comprlen);
-       tvb_memcpy(tvb, compr, offset, comprlen);
-
-       if (!compr)
+       compr = (guint8 *)tvb_memdup(NULL, tvb, offset, comprlen);
+       if (compr == NULL) {
                return NULL;
+       }
 
        /*
         * Assume that the uncompressed data is at least twice as big as
@@ -103,7 +90,7 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen)
        if (err != Z_OK) {
                inflateEnd(strm);
                g_free(strm);
-               g_free(compr);
+               wmem_free(NULL, compr);
                g_free(strmbuf);
                return NULL;
        }
@@ -165,7 +152,7 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen)
                        if (uncompr != NULL) {
                                break;
                        } else {
-                               g_free(compr);
+                               wmem_free(NULL, compr);
                                return NULL;
                        }
 
@@ -195,7 +182,7 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen)
                        if (comprlen < 10 || *c != Z_DEFLATED) {
                                inflateEnd(strm);
                                g_free(strm);
-                               g_free(compr);
+                               wmem_free(NULL, compr);
                                g_free(strmbuf);
                                return NULL;
                        }
@@ -254,7 +241,7 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen)
                        if (c - compr > comprlen) {
                                inflateEnd(strm);
                                g_free(strm);
-                               g_free(compr);
+                               wmem_free(NULL, compr);
                                g_free(strmbuf);
                                return NULL;
                        }
@@ -298,7 +285,7 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen)
                        if (err != Z_OK) {
                                g_free(strm);
                                g_free(strmbuf);
-                               g_free(compr);
+                               wmem_free(NULL, compr);
                                g_free(uncompr);
 
                                return NULL;
@@ -309,7 +296,7 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen)
                        g_free(strmbuf);
 
                        if (uncompr == NULL) {
-                               g_free(compr);
+                               wmem_free(NULL, compr);
                                return NULL;
                        }
 
@@ -326,7 +313,7 @@ tvb_uncompress(tvbuff_t *tvb, const int offset, int comprlen)
                uncompr_tvb =  tvb_new_real_data((guint8*) uncompr, bytes_out, bytes_out);
                tvb_set_free_cb(uncompr_tvb, g_free);
        }
-       g_free(compr);
+       wmem_free(NULL, compr);
        return uncompr_tvb;
 }
 #else