Changeset 4d253ae for lib/format_pktmeta.c
- Timestamp:
- 02/05/19 13:16:23 (2 years ago)
- Branches:
- develop
- Children:
- e0f2dca
- Parents:
- a86d10e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_pktmeta.c
ra86d10e r4d253ae 51 51 52 52 libtrace_meta_t *r = NULL; 53 libtrace_meta_t *f ;53 libtrace_meta_t *f = NULL; 54 54 int i; 55 55 … … 64 64 65 65 if (r == NULL) { return NULL; } 66 67 /* Allocate memory for the result */ 68 f = malloc(sizeof(libtrace_meta_t)); 69 if (f == NULL) { 70 trace_set_err(packet->trace, TRACE_ERR_OUT_OF_MEMORY, 71 "Unable to allocate memory in trace_get_meta_option()"); 72 trace_destroy_meta(r); 73 return NULL; 74 } 75 f->num = 0; 66 76 67 77 /* See if a result was found within the section */ … … 69 79 if (r->section == section && r->items[i].option == option) { 70 80 /* Create a meta structure with the single item wanted */ 71 f = malloc(sizeof(libtrace_meta_t)); 72 f->num = 1; 73 f->items = malloc(sizeof(libtrace_meta_item_t)); 74 75 f->items->option = r->items[i].option; 76 f->items->option_name = r->items[i].option_name; 77 f->items->len = r->items[i].len; 78 f->items->datatype = r->items[i].datatype; 79 f->items->data = r->items[i].data; 81 //f = malloc(sizeof(libtrace_meta_t)); 82 if (f->num == 0) { 83 f->items = malloc(sizeof(libtrace_meta_item_t)); 84 } else { 85 f->items = realloc(f->items, (f->num+1)* 86 sizeof(libtrace_meta_item_t)); 87 } 88 /* Ensure memory was allocated */ 89 if (f->items == NULL) { 90 trace_set_err(packet->trace, TRACE_ERR_OUT_OF_MEMORY, 91 "Unable to allocate memory in trace_get_meta_option()"); 92 trace_destroy_meta(r); 93 trace_destroy_meta(f); 94 return NULL; 95 } 96 97 /* Copy the data over */ 98 f->items[f->num].option = r->items[i].option; 99 f->items[f->num].option_name = r->items[i].option_name; 100 f->items[f->num].len = r->items[i].len; 101 f->items[f->num].datatype = r->items[i].datatype; 102 f->items[f->num].data = r->items[i].data; 80 103 81 104 /* delink from original structure */ 82 105 r->items[i].data = NULL; 83 106 84 trace_destroy_meta(r); 85 return f; 107 f->num += 1; 86 108 } 87 109 } 88 110 89 trace_destroy_meta(r); 90 return NULL; 111 /* Destroy the old structure */ 112 trace_destroy_meta(r); 113 114 if (f->num > 0) { 115 return f; 116 } else { 117 trace_destroy_meta(f); 118 return NULL; 119 } 91 120 } 92 121
Note: See TracChangeset
for help on using the changeset viewer.