lwm2mtlv: Fix memleaks in UAT subtree array handling

No need to allocate pointers for subtree indexes.

Change-Id: Ia1214e42d8220341454e1126878c217835788797
Reviewed-on: https://code.wireshark.org/review/31776
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Stig Bjørlykke 2019-01-28 15:35:34 +01:00 committed by Peter Wu
parent 8b75b52254
commit ab13515315
1 changed files with 12 additions and 13 deletions

View File

@ -111,12 +111,12 @@ typedef struct _lwm2m_resource_t {
char *name;
guint data_type;
gint *hf_id;
gint *ett_id;
gint ett_id;
char *field_name;
} lwm2m_resource_t;
/* RESOURCE_FILL initializes all the dynamic fields in a lwm2m_resource_t. */
#define RESOURCE_FILL NULL, NULL, NULL
#define RESOURCE_FILL NULL, -1, NULL
#define DATA_TYPE_NONE 0
#define DATA_TYPE_STRING 1
@ -404,14 +404,11 @@ static void lwm2m_resource_free_cb(void *record)
static void lwm2m_add_resource(lwm2m_resource_t *resource, hf_register_info *hf)
{
gchar *resource_abbrev;
gint *hf_id, *ett_id;
gint *hf_id;
hf_id = g_new(gint,1);
*hf_id = -1;
ett_id = g_new(gint, 1);
*ett_id = -1;
if (resource->field_name) {
resource_abbrev = g_strdup(resource->field_name);
} else {
@ -424,7 +421,7 @@ static void lwm2m_add_resource(lwm2m_resource_t *resource, hf_register_info *hf)
}
resource->hf_id = hf_id;
resource->ett_id = ett_id;
resource->ett_id = -1;
hf->p_id = hf_id;
hf->hfinfo.name = g_strdup(resource->name);
@ -485,7 +482,7 @@ static void deregister_resource_fields(void)
}
if (dynamic_ett) {
proto_add_deregistered_data(g_array_free(dynamic_ett, TRUE));
g_array_free(dynamic_ett, TRUE);
dynamic_ett = NULL;
}
}
@ -499,8 +496,9 @@ static void lwm2m_resource_post_update_cb(void)
dynamic_ett = g_array_new(TRUE, TRUE, sizeof(gint*));
for (guint i = 0; i < num_lwm2m_uat_resources; i++) {
gint *ettp = &(lwm2m_uat_resources[i].ett_id);
lwm2m_add_resource(&lwm2m_uat_resources[i], &dynamic_hf[dynamic_hf_size++]);
g_array_append_val(dynamic_ett, lwm2m_uat_resources[i].ett_id);
g_array_append_val(dynamic_ett, ettp);
}
proto_register_field_array(proto_lwm2mtlv, dynamic_hf, dynamic_hf_size);
@ -599,12 +597,12 @@ addElementTree(tvbuff_t *tvb, proto_tree *tlv_tree, lwm2mElement_t *element, con
"%02u", element->identifier);
case RESOURCE_ARRAY:
ett_id = resource ? *resource->ett_id : ett_lwm2mtlv_resourceArray;
ett_id = resource ? resource->ett_id : ett_lwm2mtlv_resourceArray;
return proto_tree_add_subtree_format(tlv_tree, tvb, 0, element->totalLength, ett_id, NULL,
"%s", identifier);
case RESOURCE:
ett_id = resource ? *resource->ett_id : ett_lwm2mtlv_resource;
ett_id = resource ? resource->ett_id : ett_lwm2mtlv_resource;
return proto_tree_add_subtree_format(tlv_tree, tvb, 0, element->totalLength, ett_id, NULL,
"%s", identifier);
}
@ -906,7 +904,7 @@ static void lwm2m_shutdown_routine(void)
proto_add_deregistered_data(static_hf);
static_hf = NULL;
proto_add_deregistered_data(g_array_free(static_ett, TRUE));
g_array_free(static_ett, TRUE);
static_ett = NULL;
}
@ -1091,8 +1089,9 @@ void proto_register_lwm2mtlv(void)
static_ett = g_array_new(TRUE, TRUE, sizeof(gint*));
for (guint i = 0; i < array_length(lwm2m_oma_resources); i++) {
gint *ettp = &(lwm2m_oma_resources[i].ett_id);
lwm2m_add_resource(&lwm2m_oma_resources[i], &static_hf[i]);
g_array_append_val(static_ett, lwm2m_oma_resources[i].ett_id);
g_array_append_val(static_ett, ettp);
}
proto_register_field_array(proto_lwm2mtlv, static_hf, array_length(lwm2m_oma_resources));