static condition* _cnd_constr_timeout(condition* cnd, va_list ap){
cnd_timeout_dat *data = NULL;
/* allocate memory */
- if((data = (cnd_timeout_dat*)malloc(sizeof(cnd_timeout_dat))) == NULL)
+ if((data = (cnd_timeout_dat*)g_malloc(sizeof(cnd_timeout_dat))) == NULL)
return NULL;
/* initialize user data */
data->start_time = time(NULL);
*/
static void _cnd_destr_timeout(condition* cnd){
/* free memory */
- free(cnd_get_user_data(cnd));
+ g_free(cnd_get_user_data(cnd));
} /* END _cnd_destr_timeout() */
/*
static condition* _cnd_constr_capturesize(condition* cnd, va_list ap){
cnd_capturesize_dat *data = NULL;
/* allocate memory */
- if((data = (cnd_capturesize_dat*)malloc(sizeof(cnd_capturesize_dat))) == NULL)
+ if((data = (cnd_capturesize_dat*)g_malloc(sizeof(cnd_capturesize_dat))) == NULL)
return NULL;
/* initialize user data */
data->max_capture_size = va_arg(ap, long);
*/
static void _cnd_destr_capturesize(condition* cnd){
/* free memory */
- free(cnd_get_user_data(cnd));
+ g_free(cnd_get_user_data(cnd));
} /* END _cnd_destr_capturesize() */
/*
if((cls = (_cnd_class*)g_hash_table_lookup(classes, class_id)) == NULL)
return NULL;
/* initialize the basic structure */
- if((cnd_ref = (condition*)malloc(sizeof(condition))) == NULL) return NULL;
+ if((cnd_ref = (condition*)g_malloc(sizeof(condition))) == NULL) return NULL;
cnd_ref->user_data = NULL;
cnd_ref->eval_func = cls->eval_func;
cnd_ref->reset_func = cls->reset_func;
/* copy the class id */
- if((id = (char*)malloc(strlen(class_id)+1)) == NULL){
- free(cnd_ref);
+ if((id = (char*)g_malloc(strlen(class_id)+1)) == NULL){
+ g_free(cnd_ref);
return NULL;
}
strcpy(id, class_id);
va_end(ap);
/* check for successful construction */
if(cnd == NULL){
- free(cnd_ref);
- free(id);
+ g_free(cnd_ref);
+ g_free(id);
}
return cnd;
} /* END cnd_new() */
/* call class specific destructor */
if(cls != NULL) (cls->destr_func)(cnd);
/* free memory */
- free(cnd->class_id);
+ g_free(cnd->class_id);
/* free basic structure */
- free(cnd);
+ g_free(cnd);
} /* END cnd_delete() */
gboolean cnd_eval(condition *cnd, ...){
return FALSE;
/* GHashTable keys need to be persistent for the lifetime of the hash
table. Allocate memory and copy the class id which we use as key. */
- if((key = (char*)malloc(strlen(class_id)+1)) == NULL) return FALSE;
+ if((key = (char*)g_malloc(strlen(class_id)+1)) == NULL) return FALSE;
strcpy(key, class_id);
/* initialize class structure */
- if((cls = (_cnd_class*)malloc(sizeof(_cnd_class))) == NULL){
- free(key);
+ if((cls = (_cnd_class*)g_malloc(sizeof(_cnd_class))) == NULL){
+ g_free(key);
return FALSE;
}
cls->constr_func = constr_func;
/* remove constructor from hash table */
g_hash_table_remove(classes, class_id);
/* free the key */
- free(pkey);
+ g_free(pkey);
pkey = NULL;
/* free the value */
- free(cls);
+ g_free(cls);
} /* END cnd_unregister_class() */
/*
if (flags & FLAG_COMPRESSED) { /* the remainder of the packet is compressed */
guint16 orig_size = tvb_get_ntohs(tvb, offset); offset += 2;
guchar *decompressed_buffer; /* Buffers for decompression */
- decompressed_buffer = (guchar*) malloc (orig_size);
+ decompressed_buffer = (guchar*) g_malloc (orig_size);
decompress_packet (tvb_get_ptr(tvb, offset, -1), tvb_length_remaining(tvb, offset),
decompressed_buffer, orig_size);
/* Now re-setup the tvb buffer to have the new data */
next_tvb = tvb_new_real_data(decompressed_buffer, orig_size, orig_size);
tvb_set_child_real_data_tvbuff(tvb, next_tvb);
add_new_data_source(pinfo, next_tvb, "Decompressed Data");
- tvb_set_free_cb(next_tvb, free);
+ tvb_set_free_cb(next_tvb, g_free);
} else {
next_tvb = tvb_new_subset(tvb, offset, -1, -1);
}
</para>
<para>
So armed with the size, a buffer is allocated to receive the uncompressed
- data using malloc, and the packet is decompressed into it.
+ data using g_malloc, and the packet is decompressed into it.
The tvb_get_ptr function is useful to get a pointer to the raw data of
the packet from the offset onwards. In this case the
decompression routine also needs to know the length, which is
Finally we add this data as a new data source, so that
the detailed display can show the decompressed bytes as well as the original.
One procedural step is to add a handler to free the data when its no longer needed.
- In this case as malloc was used to allocate the memory, free is the appropriate
+ In this case as g_malloc was used to allocate the memory, g_free is the appropriate
function.
</para>
<para>
}
if (use_default_ie_name) {
- ie->name = malloc(strlen(iename) + 1);
+ ie->name = g_malloc(strlen(iename) + 1);
if (ie->name == NULL) {
#ifdef BSSGP_DEBUG
proto_tree_add_text(bi->bssgp_tree, bi->tvb, bi->offset, 1,
}
if (use_default_ie_name) {
/* Memory has been allocated; free it */
- free(ie->name);
+ g_free(ie->name);
ie->name = NULL;
}
}
{
dcmState_t *ds;
- if (NULL == (ds = (dcmState_t *) malloc(sizeof(dcmState_t)))) {
+ if (NULL == (ds = (dcmState_t *) g_malloc(sizeof(dcmState_t)))) {
return NULL;
}
ds->pdu = 0;
else {
/* out of order packet */
if(data_length > 0 && sequence > seq[src_index] ) {
- tmp_frag = (tcp_frag *)malloc( sizeof( tcp_frag ) );
- tmp_frag->data = (guchar *)malloc( data_length );
+ tmp_frag = (tcp_frag *)g_malloc( sizeof( tcp_frag ) );
+ tmp_frag->data = (guchar *)g_malloc( data_length );
tmp_frag->seq = sequence;
tmp_frag->len = length;
tmp_frag->data_len = data_length;
} else {
frags[index] = current->next;
}
- free( current->data );
- free( current );
+ g_free( current->data );
+ g_free( current );
return 1;
}
prev = current;
current = frags[i];
while( current ) {
next = current->next;
- free( current->data );
- free( current );
+ g_free( current->data );
+ g_free( current );
current = next;
}
frags[i] = NULL;
{
tap_cmd_arg *newtca;
- newtca=malloc(sizeof(tap_cmd_arg));
+ newtca=g_malloc(sizeof(tap_cmd_arg));
newtca->next=tap_cmd_arg_list;
tap_cmd_arg_list=newtca;
newtca->cmd=cmd;
return;
}
- ip_src = malloc(edt->pi.src.len);
+ ip_src = g_malloc(edt->pi.src.len);
memcpy(ip_src, edt->pi.src.data, edt->pi.src.len);
- ip_dst = malloc(edt->pi.dst.len);
+ ip_dst = g_malloc(edt->pi.dst.len);
memcpy(ip_dst, edt->pi.dst.data, edt->pi.dst.len);
srcport = edt->pi.srcport;
dstport = edt->pi.destport;
tmp_info.src.len = 16;
}
- addr = malloc(tmp_info.src.len);
+ addr = g_malloc(tmp_info.src.len);
memcpy(addr, sctp_info->ip_src.data, tmp_info.src.len);
tmp_info.src.data = addr;
tmp_info.dst.len = 16;
}
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr, sctp_info->ip_dst.data, tmp_info.dst.len);
tmp_info.dst.data = addr;
memset(info, 0, sizeof(sctp_assoc_info_t));
info->src.type = tmp_info.src.type;
info->src.len = tmp_info.src.len;
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr,(tmp_info.src.data), tmp_info.src.len);
info->src.data = addr;
info->dst.type = tmp_info.dst.type;
info->dst.len = tmp_info.dst.len;
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr, (tmp_info.dst.data), tmp_info.dst.len);
info->dst.data = addr;
info->port1 = tmp_info.port1;
sack->tsns = NULL;
sack->src.type=tsn->src.type = tmp_info.src.type;
sack->src.len=tsn->src.len = tmp_info.src.len;
- addr = malloc(tmp_info.src.len);
+ addr = g_malloc(tmp_info.src.len);
memcpy(addr, tmp_info.src.data, tmp_info.src.len);
tsn->src.data = addr;
- addr = malloc(tmp_info.src.len);
+ addr = g_malloc(tmp_info.src.len);
memcpy(addr, tmp_info.src.data, tmp_info.src.len);
sack->src.data = addr;
sack->dst.type = tsn->dst.type = tmp_info.dst.type;
sack->dst.len =tsn->dst.len = tmp_info.dst.len;
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr, tmp_info.dst.data, tmp_info.dst.len);
tsn->dst.data = addr;
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr, tmp_info.dst.data, tmp_info.dst.len);
sack->dst.data = addr;
sack->secs=tsn->secs = (guint32)pinfo->fd->rel_secs;
store = g_malloc(sizeof (address));
store->type = AT_IPv4;;
store->len = 4;
- store->data = malloc(4);
+ store->data = g_malloc(4);
tvb_memcpy(sctp_info->tvb[chunk_number], (guint8 *)(store->data),IPV4_ADDRESS_OFFSET, 4);
info = add_address(store, info, 1);
}
store = g_malloc(sizeof (address));
store->type = AT_IPv6;;
store->len = 16;
- store->data = malloc(16);
+ store->data = g_malloc(16);
tvb_memcpy(sctp_info->tvb[chunk_number], (guint8 *)(store->data),IPV6_ADDRESS_OFFSET, IPV6_ADDRESS_LENGTH);
info = add_address(store, info, 1);
}
store = g_malloc(sizeof (address));
store->type = tmp_info.src.type;
store->len = tmp_info.src.len;
- addr = malloc(tmp_info.src.len);
+ addr = g_malloc(tmp_info.src.len);
memcpy(addr,(tmp_info.src.data),tmp_info.src.len);
store->data = addr;
info = add_address(store, info, 1);
store = g_malloc(sizeof (address));
store->type = tmp_info.dst.type;
store->len = tmp_info.dst.len;
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr,(tmp_info.dst.data),tmp_info.dst.len);
store->data = addr;
info = add_address(store, info, 2);
sack->tsns = NULL;
sack->src.type = tsn->src.type = tmp_info.src.type;
sack->src.len = tsn->src.len = tmp_info.src.len;
- addr = malloc(tmp_info.src.len);
+ addr = g_malloc(tmp_info.src.len);
memcpy(addr, tmp_info.src.data, tmp_info.src.len);
tsn->src.data = addr;
- addr = malloc(tmp_info.src.len);
+ addr = g_malloc(tmp_info.src.len);
memcpy(addr, tmp_info.src.data, tmp_info.src.len);
sack->src.data = addr;
sack->dst.type = tsn->dst.type = tmp_info.dst.type;
sack->dst.len = tsn->dst.len = tmp_info.dst.len;
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr, tmp_info.dst.data, tmp_info.dst.len);
tsn->dst.data = addr;
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr, tmp_info.dst.data, tmp_info.dst.len);
sack->dst.data = addr;
sack->secs=tsn->secs = (guint32)pinfo->fd->rel_secs;
store = g_malloc(sizeof (address));
store->type = tmp_info.src.type;
store->len = tmp_info.src.len;
- addr = malloc(tmp_info.src.len);
+ addr = g_malloc(tmp_info.src.len);
memcpy(addr,(tmp_info.src.data),tmp_info.src.len);
store->data = addr;
store = g_malloc(sizeof (address));
store->type = tmp_info.dst.type;
store->len = tmp_info.dst.len;
- addr = malloc(tmp_info.dst.len);
+ addr = g_malloc(tmp_info.dst.len);
memcpy(addr,(tmp_info.dst.data),tmp_info.dst.len);
store->data = addr;
store = g_malloc(sizeof (address));
store->type = AT_IPv4;;
store->len = 4;
- store->data = malloc(4);
+ store->data = g_malloc(4);
tvb_memcpy(sctp_info->tvb[chunk_number], (guint8 *)(store->data),IPV4_ADDRESS_OFFSET, 4);
info = add_address(store, info, info->direction);
}
store = g_malloc(sizeof (address));
store->type = AT_IPv6;;
store->len = 16;
- store->data = malloc(16);
+ store->data = g_malloc(16);
tvb_memcpy(sctp_info->tvb[chunk_number], (guint8 *)(store->data),IPV6_ADDRESS_OFFSET, IPV6_ADDRESS_LENGTH);
info = add_address(store, info, info->direction);
}
{
struct graph *g;
- g = (struct graph * )calloc (1, sizeof (struct graph));
+ g = (struct graph * )g_malloc0 (sizeof (struct graph));
graph_element_lists_initialize (g);
- g->x_axis = (struct axis * )calloc (1, sizeof (struct axis));
- g->y_axis = (struct axis * )calloc (1, sizeof (struct axis));
+ g->x_axis = (struct axis * )g_malloc0 (sizeof (struct axis));
+ g->y_axis = (struct axis * )g_malloc0 (sizeof (struct axis));
g->x_axis->g = g;
g->x_axis->flags = 0;
g->x_axis->flags |= AXIS_ORIENTATION;
#endif
gdk_pixmap_unref (g->pixmap[0]);
gdk_pixmap_unref (g->pixmap[1]);
- free (g->x_axis);
- free (g->y_axis);
- free (g->title);
+ g_free (g->x_axis);
+ g_free (g->y_axis);
+ g_free (g->title);
graph_segment_list_free (g);
graph_element_lists_free (g);
#if 0
graphs = g->next;
else
p->next = g->next;
- free (g);
+ g_free (g);
#if 0
for (tmp=graphs; tmp; tmp=tmp->next)
printf ("%p next: %p\n", tmp, tmp->next);
while (g->segments) {
segment = g->segments->next;
- free (g->segments);
+ g_free (g->segments);
g->segments = segment;
}
g->segments = NULL;
static void graph_element_lists_initialize (struct graph *g)
{
- g->elists = (struct element_list *)calloc (1, sizeof (struct element_list));
+ g->elists = (struct element_list *)g_malloc0 (sizeof (struct element_list));
}
static void graph_element_lists_make (struct graph *g)
#if 0
for (list=g->elists; list; list=list->next)
- free (list->elements);
+ g_free (list->elements);
while (g->elists->next) {
list = g->elists->next->next;
- free (g->elists->next);
+ g_free (g->elists->next);
g->elists->next = list;
}
#endif
for (list=g->elists; list; list=next_list) {
- free (list->elements);
+ g_free (list->elements);
next_list = list->next;
- free (list);
+ g_free (list);
}
g->elists = NULL; /* just to make debugging easier */
}
{
gdk_pixmap_unref (axis->pixmap[0]);
gdk_pixmap_unref (axis->pixmap[1]);
- free (axis->label);
+ g_free (axis->label);
}
static void axis_display (struct axis *axis)
struct ipoint pos, offsetpos;
GdkEvent *e=NULL;
- mg = g->magnify.g = (struct graph * )malloc (sizeof (struct graph));
+ mg = g->magnify.g = (struct graph * )g_malloc (sizeof (struct graph));
memcpy ((void * )mg, (void * )g, sizeof (struct graph));
mg->toplevel = dlg_window_new("tcp graph magnify");
new_list = mg->elists;
for ( ; list; list=list->next) {
new_list->next =
- (struct element_list * )malloc (sizeof (struct element_list));
+ (struct element_list * )g_malloc (sizeof (struct element_list));
new_list = new_list->next;
new_list->next = NULL;
new_list->elements = NULL;
gdk_pixmap_unref (mg->pixmap[0]);
gdk_pixmap_unref (mg->pixmap[1]);
for (list=mg->elists; list; list=list->next)
- free (list->elements);
+ g_free (list->elements);
while (mg->elists->next) {
list = mg->elists->next->next;
- free (mg->elists->next);
+ g_free (mg->elists->next);
mg->elists->next = list;
}
- free (g->magnify.g);
+ g_free (g->magnify.g);
g->magnify.active = 0;
}
g->s.tseq_stevens.seq_height = 4;
g->s.tseq_stevens.flags = 0;
- g->title = (char ** )malloc (2 * sizeof (char *));
+ g->title = (char ** )g_malloc (2 * sizeof (char *));
g->title[0] = "Time/Sequence Graph";
g->title[1] = NULL;
- g->y_axis->label = (char ** )malloc (3 * sizeof (char * ));
+ g->y_axis->label = (char ** )g_malloc (3 * sizeof (char * ));
g->y_axis->label[0] = "number[B]";
g->y_axis->label[1] = "Sequence";
g->y_axis->label[2] = NULL;
- g->x_axis->label = (char ** )malloc (2 * sizeof (char * ));
+ g->x_axis->label = (char ** )g_malloc (2 * sizeof (char * ));
g->x_axis->label[0] = "Time[s]";
g->x_axis->label[1] = NULL;
}
debug(DBS_FENTRY) puts ("tseq_stevens_make_elmtlist()");
if (g->elists->elements == NULL) {
int n = 1 + get_num_dsegs (g);
- e = elements = (struct element * )malloc (n*sizeof (struct element));
+ e = elements = (struct element * )g_malloc (n*sizeof (struct element));
} else
e = elements = g->elists->elements;
gdk_gc_set_foreground (g->s.tseq_tcptrace.gc_ack[1], &color);
g->elists->next = (struct element_list * )
- malloc (sizeof (struct element_list));
+ g_malloc (sizeof (struct element_list));
g->elists->next->next = NULL;
g->elists->next->elements = NULL;
- g->title = (char ** )malloc (2 * sizeof (char *));
+ g->title = (char ** )g_malloc (2 * sizeof (char *));
g->title[0] = "Time/Sequence Graph";
g->title[1] = NULL;
- g->y_axis->label = (char ** )malloc (3 * sizeof (char * ));
+ g->y_axis->label = (char ** )g_malloc (3 * sizeof (char * ));
g->y_axis->label[0] = "number[B]";
g->y_axis->label[1] = "Sequence";
g->y_axis->label[2] = NULL;
- g->x_axis->label = (char ** )malloc (2 * sizeof (char * ));
+ g->x_axis->label = (char ** )g_malloc (2 * sizeof (char * ));
g->x_axis->label[0] = "Time[s]";
g->x_axis->label[1] = NULL;
}
if (g->elists->elements == NULL) {
int n = 1 + 4*get_num_acks(g);
- e0 = elements0 = (struct element * )malloc (n*sizeof (struct element));
+ e0 = elements0 = (struct element * )g_malloc (n*sizeof (struct element));
} else
e0 = elements0 = g->elists->elements;
if (g->elists->next->elements == NULL ) {
int n = 1 + 3*get_num_dsegs(g);
- e1 = elements1 = (struct element * )malloc (n*sizeof (struct element));
+ e1 = elements1 = (struct element * )g_malloc (n*sizeof (struct element));
} else
e1 = elements1 = g->elists->next->elements;
if (g->elists->elements == NULL) {
int n = 1 + get_num_dsegs (g);
- e = elements = (struct element * )malloc (n*sizeof (struct element));
+ e = elements = (struct element * )g_malloc (n*sizeof (struct element));
} else
e = elements = g->elists->elements;
g->s.tput.height = 4;
g->s.tput.nsegs = 20;
- g->title = (char ** )malloc (2 * sizeof (char *));
+ g->title = (char ** )g_malloc (2 * sizeof (char *));
g->title[0] = "Throughput Graph";
g->title[1] = NULL;
- g->y_axis->label = (char ** )malloc (3 * sizeof (char * ));
+ g->y_axis->label = (char ** )g_malloc (3 * sizeof (char * ));
g->y_axis->label[0] = "[B/s]";
g->y_axis->label[1] = "Throughput";
g->y_axis->label[2] = NULL;
- g->x_axis->label = (char ** )malloc (2 * sizeof (char * ));
+ g->x_axis->label = (char ** )g_malloc (2 * sizeof (char * ));
g->x_axis->label[0] = "Time[s]";
g->x_axis->label[1] = NULL;
g->s.tput.flags = 0;
g->s.rtt.height = 4;
g->s.rtt.flags = 0;
- g->title = (char ** )malloc (2 * sizeof (char *));
+ g->title = (char ** )g_malloc (2 * sizeof (char *));
g->title[0] = "Round Trip Time Graph";
g->title[1] = NULL;
- g->y_axis->label = (char ** )malloc (3 * sizeof (char * ));
+ g->y_axis->label = (char ** )g_malloc (3 * sizeof (char * ));
g->y_axis->label[0] = "RTT [s]";
g->y_axis->label[1] = NULL;
- g->x_axis->label = (char ** )malloc (2 * sizeof (char * ));
+ g->x_axis->label = (char ** )g_malloc (2 * sizeof (char * ));
g->x_axis->label[0] = "Sequence Number[B]";
g->x_axis->label[1] = NULL;
}
{
struct unack *u;
- u = (struct unack * )malloc (sizeof (struct unack));
+ u = (struct unack * )g_malloc (sizeof (struct unack));
if (!u)
return NULL;
u->next = NULL;
if (dead==list) {
*l = list->next;
- free (list);
+ g_free (list);
} else
for (u=list; u; u=u->next)
if (u->next == dead) {
u->next = u->next->next;
- free (dead);
+ g_free (dead);
break;
}
}
if (g->elists->elements == NULL) {
int n = 1 + get_num_dsegs (g);
- e = elements = (struct element * )malloc (n*sizeof (struct element));
+ e = elements = (struct element * )g_malloc (n*sizeof (struct element));
} else {
e = elements = g->elists->elements;
}
g_free(work);
}
- /* malloc and insert the new one */
+ /* g_malloc and insert the new one */
work = g_malloc(sizeof(*geom));
*work = *geom;
key = g_strdup(name);