@@ -117,14 +117,7 @@ void breakpoint(void)
117
117
118
118
struct print_arg * alloc_arg (void )
119
119
{
120
- struct print_arg * arg ;
121
-
122
- arg = malloc_or_die (sizeof (* arg ));
123
- if (!arg )
124
- return NULL ;
125
- memset (arg , 0 , sizeof (* arg ));
126
-
127
- return arg ;
120
+ return calloc (1 , sizeof (struct print_arg ));
128
121
}
129
122
130
123
struct cmdline {
@@ -619,14 +612,7 @@ void pevent_print_printk(struct pevent *pevent)
619
612
620
613
static struct event_format * alloc_event (void )
621
614
{
622
- struct event_format * event ;
623
-
624
- event = malloc (sizeof (* event ));
625
- if (!event )
626
- return NULL ;
627
- memset (event , 0 , sizeof (* event ));
628
-
629
- return event ;
615
+ return calloc (1 , sizeof (struct event_format ));
630
616
}
631
617
632
618
static void add_event (struct pevent * pevent , struct event_format * event )
@@ -1240,8 +1226,10 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1240
1226
1241
1227
last_token = token ;
1242
1228
1243
- field = malloc_or_die (sizeof (* field ));
1244
- memset (field , 0 , sizeof (* field ));
1229
+ field = calloc (1 , sizeof (* field ));
1230
+ if (!field )
1231
+ goto fail ;
1232
+
1245
1233
field -> event = event ;
1246
1234
1247
1235
/* read the rest of the type */
@@ -2181,8 +2169,9 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
2181
2169
if (test_type_token (type , token , EVENT_DELIM , "," ))
2182
2170
goto out_free ;
2183
2171
2184
- field = malloc_or_die (sizeof (* field ));
2185
- memset (field , 0 , sizeof (* field ));
2172
+ field = calloc (1 , sizeof (* field ));
2173
+ if (!field )
2174
+ goto out_free ;
2186
2175
2187
2176
value = arg_eval (arg );
2188
2177
if (value == NULL )
@@ -5106,12 +5095,11 @@ int pevent_register_print_function(struct pevent *pevent,
5106
5095
remove_func_handler (pevent , name );
5107
5096
}
5108
5097
5109
- func_handle = malloc ( sizeof (* func_handle ));
5098
+ func_handle = calloc ( 1 , sizeof (* func_handle ));
5110
5099
if (!func_handle ) {
5111
5100
do_warning ("Failed to allocate function handler" );
5112
5101
return PEVENT_ERRNO__MEM_ALLOC_FAILED ;
5113
5102
}
5114
- memset (func_handle , 0 , sizeof (* func_handle ));
5115
5103
5116
5104
func_handle -> ret_type = ret_type ;
5117
5105
func_handle -> name = strdup (name );
@@ -5210,13 +5198,12 @@ int pevent_register_event_handler(struct pevent *pevent,
5210
5198
5211
5199
not_found :
5212
5200
/* Save for later use. */
5213
- handle = malloc ( sizeof (* handle ));
5201
+ handle = calloc ( 1 , sizeof (* handle ));
5214
5202
if (!handle ) {
5215
5203
do_warning ("Failed to allocate event handler" );
5216
5204
return PEVENT_ERRNO__MEM_ALLOC_FAILED ;
5217
5205
}
5218
5206
5219
- memset (handle , 0 , sizeof (* handle ));
5220
5207
handle -> id = id ;
5221
5208
if (event_name )
5222
5209
handle -> event_name = strdup (event_name );
@@ -5245,13 +5232,10 @@ int pevent_register_event_handler(struct pevent *pevent,
5245
5232
*/
5246
5233
struct pevent * pevent_alloc (void )
5247
5234
{
5248
- struct pevent * pevent ;
5235
+ struct pevent * pevent = calloc ( 1 , sizeof ( * pevent )) ;
5249
5236
5250
- pevent = malloc (sizeof (* pevent ));
5251
- if (!pevent )
5252
- return NULL ;
5253
- memset (pevent , 0 , sizeof (* pevent ));
5254
- pevent -> ref_count = 1 ;
5237
+ if (pevent )
5238
+ pevent -> ref_count = 1 ;
5255
5239
5256
5240
return pevent ;
5257
5241
}
0 commit comments