@@ -97,7 +97,11 @@ hwloc_distrib_root_levels(hwloc_topology_t topology,
97
97
const unsigned long flags )
98
98
{
99
99
unsigned i ;
100
- struct hwloc_distrib_level * levels = malloc (n_types * sizeof (* levels ));
100
+ unsigned arity ;
101
+ hwloc_obj_t parent ;
102
+ struct hwloc_distrib_level * levels ;
103
+
104
+ levels = malloc (n_types * sizeof (* levels ));
101
105
if (levels == NULL )
102
106
return NULL ;
103
107
@@ -118,8 +122,6 @@ hwloc_distrib_root_levels(hwloc_topology_t topology,
118
122
qsort (levels , n_types , sizeof (* levels ), hwloc_distrib_level_cmp_depth );
119
123
120
124
// Walk from top to bottom and set arity to the maximum arity below root field.
121
- unsigned arity ;
122
- hwloc_obj_t parent ;
123
125
124
126
parent = root ;
125
127
for (i = 0 ; i < n_types ; i ++ ){
@@ -229,7 +231,9 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology,
229
231
230
232
unsigned i = 0 , n = 0 ;
231
233
hwloc_obj_t obj , root = hwloc_get_obj_by_depth (topology , 0 , 0 );
232
-
234
+ hwloc_obj_type_t * levels ;
235
+ struct hwloc_distrib_iterator * it ;
236
+
233
237
// Count depths with a non empty cpuset.
234
238
obj = root ;
235
239
while (obj ){
@@ -240,9 +244,8 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology,
240
244
obj = obj -> first_child ;
241
245
}
242
246
243
- hwloc_obj_type_t levels [n ];
244
-
245
247
// fill levels array.
248
+ levels = malloc (sizeof (* levels ) * n );
246
249
obj = root ;
247
250
while (obj ){
248
251
if ( obj -> cpuset != NULL && !hwloc_bitmap_iszero (obj -> cpuset ) && hwloc_get_type_depth (topology , obj -> type ) >= 0 ){
@@ -254,10 +257,10 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology,
254
257
obj = obj -> first_child ;
255
258
}
256
259
257
- struct hwloc_distrib_iterator * it = malloc (sizeof (* it ) + sizeof (hwloc_obj_t ) + sizeof (struct hwloc_distrib_level * ));
260
+ it = malloc (sizeof (* it ) + sizeof (hwloc_obj_t ) + sizeof (struct hwloc_distrib_level * ));
258
261
259
262
if (it == NULL )
260
- return NULL ;
263
+ goto failure ;
261
264
262
265
it -> roots = (hwloc_obj_t * ) ((char * )it + sizeof (* it ));
263
266
* it -> roots = root ;
@@ -268,11 +271,17 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology,
268
271
269
272
* it -> levels = hwloc_distrib_root_levels (topology , root , levels , n , flags );
270
273
271
- if (* it -> levels == NULL ){
272
- free ( it ) ;
273
- return NULL ;
274
- }
274
+ if (* it -> levels == NULL )
275
+ goto failure_with_it ;
276
+
277
+ free ( levels );
275
278
return it ;
279
+
280
+ failure_with_it :
281
+ free (it );
282
+ failure :
283
+ free (levels );
284
+ return NULL ;
276
285
}
277
286
278
287
void hwloc_distrib_destroy_iterator (struct hwloc_distrib_iterator * it ){
0 commit comments