convert some uses of tvb_get_string() to ep_tvb_get_string()
authorsahlberg <sahlberg@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 24 Jul 2005 02:43:41 +0000 (02:43 +0000)
committersahlberg <sahlberg@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 24 Jul 2005 02:43:41 +0000 (02:43 +0000)
there was at least one obvious memleak in one of the uses of tvb_get_string()

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@15027 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-3g-a11.c
epan/dissectors/packet-afp.c
epan/dissectors/packet-aim-messaging.c
epan/dissectors/packet-aim.c
epan/dissectors/packet-ansi_a.c
epan/dissectors/packet-atalk.c
epan/dissectors/packet-bacapp.c
epan/dissectors/packet-dsi.c
epan/dissectors/packet-fix.c
epan/dissectors/packet-gtp.c
epan/dissectors/packet-icep.c

index c077a54aa9113fe4edbc9e056dbc40918313f92d..550c213b477dffa8453c16fe4651df9c7439907b 100644 (file)
@@ -390,10 +390,9 @@ dissect_a11_radius( tvbuff_t *tvb, int offset, proto_tree *tree, int app_len)
       /**** ad-hoc ***/
       if(radius_type == 31)
       {
-       str_val = tvb_get_string(tvb,offset+2,radius_len-2);
+       str_val = ep_tvb_get_string(tvb,offset+2,radius_len-2);
         proto_tree_add_text(radius_tree, tvb, offset, radius_len,
             "MSID: %s", str_val);
-        g_free(str_val);
       }
       else if (radius_type == 46)
       {
@@ -479,11 +478,10 @@ dissect_a11_radius( tvbuff_t *tvb, int offset, proto_tree *tree, int app_len)
             a11_airlink_types,"Unknown"));
           break;
         case ATTR_TYPE_STR:
-          str_val = tvb_get_string(tvb,offset+radius_offset+2,attribute_len-2);
+          str_val = ep_tvb_get_string(tvb,offset+radius_offset+2,attribute_len-2);
           proto_tree_add_text(radius_tree, tvb, offset+radius_offset,
              attribute_len,
             "3GPP2: %s (%s)", attrs[attribute_type].attrname, str_val);
-          g_free(str_val);
           break;
         case ATTR_TYPE_NULL:
           break;
index 2344de22da657b10583d9ac8f868030d66112141..a518940ba6963c25d286928f9581ba7fa3e73d7b 100644 (file)
@@ -1597,7 +1597,7 @@ name_in_bitmap(tvbuff_t *tvb, gint offset, guint16 bitmap, int isdir)
                        tp_ofs = nameoff +org_offset;
                        len = tvb_get_guint8(tvb, tp_ofs);
                        tp_ofs++;
-                       name = tvb_get_string(tvb, tp_ofs, len);
+                       name = ep_tvb_get_string(tvb, tp_ofs, len);
                        return name;
                }
                offset += 2;
@@ -1635,7 +1635,7 @@ name_in_bitmap(tvbuff_t *tvb, gint offset, guint16 bitmap, int isdir)
                        tp_ofs = nameoff +org_offset +4;
                        len16 = tvb_get_ntohs(tvb, tp_ofs);
                        tp_ofs += 2;
-                       name = tvb_get_string(tvb, tp_ofs, len16);
+                       name = ep_tvb_get_string(tvb, tp_ofs, len16);
                        return name;
                }
        }
@@ -2064,7 +2064,6 @@ loop_record(tvbuff_t *tvb, proto_tree *ptree, gint offset,
                        }
                        if (name) {
                                item = proto_tree_add_text(ptree, tvb, offset, size, "%s", name);
-                               g_free(name);
                        }
                        else {
                                item = proto_tree_add_text(ptree, tvb, offset, size, "line %d", i+1);
index 1cd415b62524793d37524602724d64c4caddeec9..92131fc0d973c69466d5d1bf315030bc642aef33 100644 (file)
@@ -410,7 +410,7 @@ static int dissect_aim_rendezvous_extended_message(tvbuff_t *tvb, proto_tree *ms
        proto_tree_add_item(msg_tree, hf_aim_rendezvous_extended_data_message_priority_code, tvb, offset, 2, TRUE); offset+=2;
        text_length = tvb_get_letohs(tvb, offset);
        proto_tree_add_item(msg_tree, hf_aim_rendezvous_extended_data_message_text_length, tvb, offset, 2, TRUE); offset+=2;
-       text = tvb_get_string(tvb, offset, text_length);
+       text = ep_tvb_get_string(tvb, offset, text_length);
        proto_tree_add_text(msg_tree, tvb, offset, text_length, "Text: %s", text); offset+=text_length;
        offset = tvb->length;
        
index 9b587cbf9340594d3fef31cd093ad9efa9aeed39..fe2857874a54a1f8eade948b6fa0cb98c1d0946e 100644 (file)
@@ -1114,9 +1114,8 @@ int dissect_aim_tlv_value_string (proto_item *ti, guint16 valueid _U_, tvbuff_t
    gint string_len;
 
    string_len = tvb_length(tvb);
-   buf = tvb_get_string(tvb, 0, string_len);
+   buf = ep_tvb_get_string(tvb, 0, string_len);
    proto_item_set_text(ti, "Value: %s", format_text(buf, string_len));
-   g_free(buf);
    return string_len;
 }
 
@@ -1205,14 +1204,13 @@ int dissect_aim_tlv_value_messageblock (proto_item *ti, guint16 valueid _U_, tvb
     offset += 2;
 
     /* The actual message */
-    buf = tvb_get_string(tvb, offset, blocklen - 4 );
+    buf = ep_tvb_get_string(tvb, offset, blocklen - 4 );
     proto_item_set_text(ti, "Message: %s",
                         format_text(buf, blocklen - 4));
     proto_tree_add_item(entry, hf_aim_messageblock_message, tvb, offset, 
                        blocklen-4,
                        FALSE);
     offset += tvb_length_remaining(tvb, offset);
-    g_free(buf);
   }
 
   return offset;
index dd4757a0fd4ebdb5580b22dbe87c7e98bbdcc60d..8b7d4fba664e96f467c3b709c42065bc60e88cba 100644 (file)
@@ -1417,11 +1417,10 @@ elem_mid(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint len, gchar *add_
        a_bigbuf[0] = Dgt_msid.out[(oct & 0xf0) >> 4];
        curr_offset++;
 
-       poctets = tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
+       poctets = ep_tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
 
        my_dgt_tbcd_unpack(&a_bigbuf[1], poctets, len - (curr_offset - offset),
            &Dgt_msid);
-       g_free(poctets);
 
        proto_tree_add_string_format(tree,
            ((oct & 0x07) == 1) ? hf_ansi_a_min : hf_ansi_a_imsi,
@@ -2746,7 +2745,7 @@ elem_clg_party_ascii_num(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint
        curr_offset++;
     }
 
-    poctets = tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
+    poctets = ep_tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
 
     proto_tree_add_string_format(tree, hf_ansi_a_clg_party_ascii_num,
        tvb, curr_offset, len - (curr_offset - offset),
@@ -2757,7 +2756,6 @@ elem_clg_party_ascii_num(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint
     curr_offset += len - (curr_offset - offset);
 
     sprintf(add_string, " - (%s)", poctets);
-    g_free(poctets);
 
     EXTRANEOUS_DATA_CHECK(len, curr_offset - offset);
 
@@ -3258,11 +3256,10 @@ elem_cld_party_bcd_num(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint le
 
     curr_offset++;
 
-    poctets = tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
+    poctets = ep_tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
 
     my_dgt_tbcd_unpack(a_bigbuf, poctets, len - (curr_offset - offset),
        &Dgt_tbcd);
-    g_free(poctets);
 
     proto_tree_add_string_format(tree, hf_ansi_a_cld_party_bcd_num,
        tvb, curr_offset, len - (curr_offset - offset),
@@ -3396,11 +3393,10 @@ elem_clg_party_bcd_num(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint le
        curr_offset++;
     }
 
-    poctets = tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
+    poctets = ep_tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
 
     my_dgt_tbcd_unpack(a_bigbuf, poctets, len - (curr_offset - offset),
        &Dgt_tbcd);
-    g_free(poctets);
 
     proto_tree_add_string_format(tree, hf_ansi_a_clg_party_bcd_num,
        tvb, curr_offset, len - (curr_offset - offset),
@@ -5286,7 +5282,7 @@ elem_cld_party_ascii_num(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint
 
     curr_offset++;
 
-    poctets = tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
+    poctets = ep_tvb_get_string(tvb, curr_offset, len - (curr_offset - offset));
 
     proto_tree_add_string_format(tree, hf_ansi_a_cld_party_ascii_num,
        tvb, curr_offset, len - (curr_offset - offset),
@@ -5297,7 +5293,6 @@ elem_cld_party_ascii_num(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint
     curr_offset += len - (curr_offset - offset);
 
     sprintf(add_string, " - (%s)", poctets);
-    g_free(poctets);
 
     EXTRANEOUS_DATA_CHECK(len, curr_offset - offset);
 
index 7f48b4e3465c0cdb9ebd0c3532dd08bb49f3b798..72cfa3b48f50aef71b613ada91bcf8fbd0b96b57 100644 (file)
@@ -518,14 +518,13 @@ static int dissect_pascal_string(tvbuff_t *tvb, int offset, proto_tree *tree,
                 * code, we could perhaps avoid allocating and freeing
                 * this string buffer.
                 */
-               tmp = tvb_get_string(tvb, offset, len);
+               tmp = ep_tvb_get_string(tvb, offset, len);
                item = proto_tree_add_string(tree, hf_index, tvb, offset-1, len+1, tmp);
 
                subtree = proto_item_add_subtree(item, ett_pstring);
                proto_tree_add_text(subtree, tvb, offset-1, 1, "Length: %d", len);
                proto_tree_add_text(subtree, tvb, offset, len, "Data: %s", tmp);
 
-               g_free(tmp);
        }
        offset += len;
 
@@ -1053,9 +1052,8 @@ dissect_asp_reply_get_status(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *
                                break;
                        case 4: /* DNS */
                                if (len > 2) {
-                                       tmp = tvb_get_string(tvb, ofs +2, len -2);
+                                       tmp = ep_tvb_get_string(tvb, ofs +2, len -2);
                                        ti = proto_tree_add_text(adr_tree, tvb, ofs, len, "dns %s", tmp);
-                                       g_free(tmp);
                                        break;
                                }
                                /* else fall to default malformed record */
@@ -1092,14 +1090,13 @@ dissect_asp_reply_get_status(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *
 
                ofs = utf_ofs;
                ulen = tvb_get_ntohs(tvb, ofs);
-               tmp = tvb_get_string(tvb, ofs + 2, ulen);
+               tmp = ep_tvb_get_string(tvb, ofs + 2, ulen);
                ti = proto_tree_add_text(tree, tvb, ofs, ulen +2, "UTF8 server name: %s", tmp);
                sub_tree = proto_item_add_subtree(ti, ett_asp_utf8_name);
                proto_tree_add_uint(sub_tree, hf_asp_server_utf8_name_len, tvb, ofs, 2, ulen);
                ofs += 2;               
                proto_tree_add_string(sub_tree, hf_asp_server_utf8_name, tvb, ofs, ulen, tmp);
                ofs += ulen;
-               g_free(tmp);
        }
        /* FIXME: offset is not updated */
        return offset;
index 766711e9d671859aba7b0625ca95c93daea56599..d46bfa20a6257f355697dacf0b26493ced0ed9ee 100644 (file)
@@ -2189,7 +2189,7 @@ fCharacterString (tvbuff_t *tvb, proto_tree *tree, guint offset, guint8 *label)
                         * other dissectors need to handle various
                         * character encodings.
                         */
-                       str_val = tvb_get_string(tvb, offset, l);
+                       str_val = ep_tvb_get_string(tvb, offset, l);
                        /** this decoding may be not correct for multi-byte characters, Lka */
                        switch (character_set) {
                        case 0x00:      /* ANSI_X3.4 */
@@ -2215,7 +2215,6 @@ fCharacterString (tvbuff_t *tvb, proto_tree *tree, guint offset, guint8 *label)
                                break;
                        }
                        proto_tree_add_text(tree, tvb, offset, l, "%s'%s'", LABEL(label), out);
-                       g_free(str_val);
                        lvt-=l;
                        offset+=l;
                } while (lvt > 0);
index 04f1415bb8970e81e99ba2a384787b4130561ed5..75c1eaed994d28adcb3a0d274d56b7de63c2f7ea 100644 (file)
@@ -414,10 +414,9 @@ dissect_dsi_reply_get_status(tvbuff_t *tvb, proto_tree *tree, gint offset)
                        case 4: /* DNS */
                        case 5: /* SSH tunnel */
                                if (len > 2) {
-                                       tmp = tvb_get_string(tvb, ofs +2, len -2);
+                                       tmp = ep_tvb_get_string(tvb, ofs +2, len -2);
                                        ti = proto_tree_add_text(adr_tree, tvb, ofs, len, "%s: %s", 
                                                                (type==4)?"dns":"ssh tunnel", tmp);
-                                       g_free(tmp);
                                        break;
                                }
                                else {
@@ -468,14 +467,13 @@ dissect_dsi_reply_get_status(tvbuff_t *tvb, proto_tree *tree, gint offset)
 
                ofs = utf_ofs;
                ulen = tvb_get_ntohs(tvb, ofs);
-               tmp = tvb_get_string(tvb, ofs + 2, ulen);
+               tmp = ep_tvb_get_string(tvb, ofs + 2, ulen);
                ti = proto_tree_add_text(tree, tvb, ofs, ulen + 2, "UTF8 server name: %s", tmp);
                sub_tree = proto_item_add_subtree(ti, ett_dsi_utf8_name);
                proto_tree_add_uint(sub_tree, hf_dsi_utf8_server_name_len, tvb, ofs, 2, ulen);
                ofs += 2;
                proto_tree_add_string(sub_tree, hf_dsi_utf8_server_name, tvb, ofs, ulen, tmp);
                ofs += ulen;
-               g_free(tmp);
        }
 
        return offset;
index aeacf739caf143af7e0869d2bd64e91887a84c00..beae7737b94d854125577671bed80199a80e1efc 100644 (file)
@@ -868,9 +868,8 @@ dissect_fix(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     }
 
     if (check_col(pinfo->cinfo, COL_INFO)) {
-        value = tvb_get_string(tvb, value_offset, value_len);
+        value = ep_tvb_get_string(tvb, value_offset, value_len);
         col_add_fstr(pinfo->cinfo, COL_INFO, "%s", (char *)g_datalist_get_data(&msg_types, value));
-        g_free(value);
     }
 
     /* In the interest of speed, if "tree" is NULL, don't do any work not
@@ -926,11 +925,10 @@ dissect_fix(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                    packet. */
                 return TRUE;
             }
-            tag_str = tvb_get_string(tvb, field_offset, tag_len);
+            tag_str = ep_tvb_get_string(tvb, field_offset, tag_len);
             tag = atoi(tag_str);
-            g_free(tag_str);
 
-            value = tvb_get_string(tvb, value_offset, value_len);
+            value = ep_tvb_get_string(tvb, value_offset, value_len);
 
             switch(tag) {
                 case 1: /* Field Account */
@@ -2916,7 +2914,6 @@ dissect_fix(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
             field_offset = offset = ctrla_offset + 1;
             ctrla_offset = tvb_find_guint8(tvb, field_offset, -1, 0x01);
 
-            g_free(value);
             tag_str = NULL;
         }
     }
index d713e6850ffb861c28f0c1732496112f66f112dc..794cce01cf78d41b3bb97d64a9ad7e4f968baf44 100644 (file)
@@ -3144,7 +3144,7 @@ decode_apn(tvbuff_t *tvb, int offset, guint16 length, proto_tree *tree) {
                name_len = tvb_get_guint8 (tvb, offset);
 
                if (name_len < 0x20) {
-                       apn = tvb_get_string(tvb, offset + 1, length - 1);
+                       apn = ep_tvb_get_string(tvb, offset + 1, length - 1);
                        for (;;) {
                                if (name_len >= length - 1) break;
                                tmp = name_len;
@@ -3152,10 +3152,9 @@ decode_apn(tvbuff_t *tvb, int offset, guint16 length, proto_tree *tree) {
                                apn[tmp] = '.';
                        }
                } else
-                       apn = tvb_get_string(tvb, offset, length);
+                       apn = ep_tvb_get_string(tvb, offset, length);
 
                proto_tree_add_string (tree, hf_gtp_apn, tvb, offset, length, apn);
-               g_free(apn);
        }
 }
 
index af9a36d9e8c6b3f4d8561b8ef28b3fea201685a0..2c5b51cbd21438d7199b542eadc92f7b49173f34 100644 (file)
@@ -158,8 +158,6 @@ static packet_info *mypinfo;
  * This function dissects an "Ice string", adds hf to "tree" and returns consumed 
  * bytes in "*consumed", if errors "*consumed" is -1.
  *
- * Memory for the new string "*dest" is obtained with g_malloc, and caller 
- * is responsible for it (i.e. don't forget to g_free() it if you pass *dest != NULL).
  * "*dest" is a null terminated version of the dissected Ice string.
  */
 static void dissect_ice_string(proto_tree *tree, int hf_icep, 
@@ -258,7 +256,7 @@ static void dissect_ice_string(proto_tree *tree, int hf_icep,
        
                
        if ( Size != 0 ) {
-               s = tvb_get_string(tvb, offset, Size);
+               s = ep_tvb_get_string(tvb, offset, Size);
                if (tree && add_hf)
                        proto_tree_add_string(tree, hf_icep, tvb, offset, Size, s);
        } else {
@@ -270,8 +268,6 @@ static void dissect_ice_string(proto_tree *tree, int hf_icep,
        
        if ( dest != NULL )
                *dest = s;
-       else
-               g_free(s);
        
        offset += Size;
        (*consumed) += Size;
@@ -484,7 +480,6 @@ static void dissect_ice_context(proto_tree *tree, tvbuff_t *tvb, guint32 offset,
                
                if ( consumed_key == -1 ) {
                        (*consumed) = -1;
-                       g_free(str_key);
                        return;
                }
                
@@ -496,8 +491,6 @@ static void dissect_ice_context(proto_tree *tree, tvbuff_t *tvb, guint32 offset,
                
                if ( consumed_value == -1 ) {
                        (*consumed) = -1;
-                       g_free(str_value);
-                       g_free(str_key);
                        return;
                }
                
@@ -513,8 +506,6 @@ static void dissect_ice_context(proto_tree *tree, tvbuff_t *tvb, guint32 offset,
                                            str_key, str_value);
                }
                
-               g_free(str_value);
-               g_free(str_key);
        }
 }
 
@@ -733,8 +724,6 @@ static void dissect_icep_request_common(tvbuff_t *tvb, guint32 offset,
                                col_append_fstr(mypinfo->cinfo, COL_INFO, " %s.%s()", 
                                                namestr, opstr);
                        }
-                       g_free(opstr);
-                       g_free(namestr);
                        opstr = NULL;
                        namestr = NULL;
                }
@@ -790,10 +779,6 @@ static void dissect_icep_request_common(tvbuff_t *tvb, guint32 offset,
        
 error:
        (*total_consumed) = -1;
-       if (namestr)
-               g_free(namestr);
-       if (opstr)
-               g_free(opstr);
 }