Skip to content

Commit 4d4fa28

Browse files
committed
opal: fix coverity issues
Fix CID 1345825 (1 of 1): Dereference before null check (REVERSE_INULL): ib_proc should not be NULL in this case. Removed the check and added a check for NULL after OBJ_NEW. CID 1269821 (1 of 1): Dereference null return value (NULL_RETURNS): I labeled this one as a false positive (which it is) but the code in question could stand be be cleaned up. Fix CID 1356424 (1 of 1): Argument cannot be negative (NEGATIVE_RETURNS): While trying to silence another Coverity issue another was flagged. Protect the close of fd with if (fd >= 0). CID 70772 (1 of 1): Dereference null return value (NULL_RETURNS): CID 70773 (1 of 1): Dereference null return value (NULL_RETURNS): CID 70774 (1 of 1): Dereference null return value (NULL_RETURNS): None of these are errors and are intentional but now that we have a list release function use that to make these go away. The cleanup is similar to CID 1269821. Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 013aec8 commit 4d4fa28

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

opal/class/opal_graph.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
34
* University Research and Technology
@@ -10,6 +11,8 @@
1011
* Copyright (c) 2004-2005 The Regents of the University of California.
1112
* All rights reserved.
1213
* Copyright (c) 2007 Voltaire All rights reserved.
14+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
15+
* reserved.
1316
* $COPYRIGHT$
1417
*
1518
* Additional copyrights may follow
@@ -149,13 +152,7 @@ static void opal_graph_construct(opal_graph_t *graph)
149152

150153
static void opal_graph_destruct(opal_graph_t *graph)
151154
{
152-
opal_adjacency_list_t *aj_list;
153-
154-
while (false == opal_list_is_empty(graph->adjacency_list)) {
155-
aj_list = (opal_adjacency_list_t *)opal_list_remove_first(graph->adjacency_list);
156-
OBJ_RELEASE(aj_list);
157-
}
158-
OBJ_RELEASE(graph->adjacency_list);
155+
OPAL_LIST_RELEASE(graph->adjacency_list);
159156
graph->number_of_vertices = 0;
160157
graph->number_of_edges = 0;
161158
}
@@ -174,15 +171,8 @@ static void opal_adjacency_list_construct(opal_adjacency_list_t *aj_list)
174171

175172
static void opal_adjacency_list_destruct(opal_adjacency_list_t *aj_list)
176173
{
177-
opal_graph_edge_t *edge;
178-
179174
aj_list->vertex = NULL;
180-
while (false == opal_list_is_empty(aj_list->edges)) {
181-
edge = (opal_graph_edge_t *)opal_list_remove_first(aj_list->edges);
182-
OBJ_RELEASE(edge);
183-
}
184-
OBJ_RELEASE(aj_list->edges);
185-
175+
OPAL_LIST_RELEASE(aj_list->edges);
186176
}
187177

188178
/**
@@ -349,14 +339,9 @@ void opal_graph_remove_vertex(opal_graph_t *graph, opal_graph_vertex_t *vertex)
349339
opal_adjacency_list_t *adj_list;
350340
opal_graph_edge_t *edge;
351341

352-
/**
353-
* remove all the edges of this vertex and destruct them.
354-
*/
342+
/* do not need to remove all the edges of this vertex and destruct them as
343+
* they will be released in the destructor for adj_list */
355344
adj_list = vertex->in_adj_list;
356-
while (false == opal_list_is_empty(adj_list->edges)) {
357-
edge = (opal_graph_edge_t *)opal_list_remove_first(adj_list->edges);
358-
OBJ_RELEASE(edge);
359-
}
360345
/**
361346
* remove the adjscency list of this vertex from the graph and
362347
* destruct it.

opal/mca/btl/openib/btl_openib_endpoint.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,7 @@ void mca_btl_openib_endpoint_connected(mca_btl_openib_endpoint_t *endpoint)
632632
/* Process pending packet on the endpoint */
633633

634634
/* While there are frags in the list, process them */
635-
while (!opal_list_is_empty(&(endpoint->pending_lazy_frags))) {
636-
frag_item = opal_list_remove_first(&(endpoint->pending_lazy_frags));
635+
while (NULL != (frag_item = opal_list_remove_first(&(endpoint->pending_lazy_frags)))) {
637636
frag = to_send_frag(frag_item);
638637
/* We need to post this one */
639638

opal/mca/btl/openib/btl_openib_proc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
34
* University Research and Technology
@@ -15,6 +16,8 @@
1516
* Copyright (c) 2015 Research Organization for Information Science
1617
* and Technology (RIST). All rights reserved.
1718
* Copyright (c) 2015 Mellanox Technologies. All rights reserved.
19+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
20+
* reserved.
1821
*
1922
* $COPYRIGHT$
2023
*
@@ -184,6 +187,9 @@ mca_btl_openib_proc_t* mca_btl_openib_proc_get_locked(opal_proc_t* proc)
184187
/* First time, gotta create a new IB proc
185188
* out of the opal_proc ... */
186189
ib_proc = OBJ_NEW(mca_btl_openib_proc_t);
190+
if (NULL == ib_proc) {
191+
return NULL;
192+
}
187193

188194
/* Initialize number of peer */
189195
ib_proc->proc_endpoint_count = 0;
@@ -321,10 +327,9 @@ mca_btl_openib_proc_t* mca_btl_openib_proc_get_locked(opal_proc_t* proc)
321327

322328
err_exit:
323329

324-
fprintf(stderr,"%d: error exit from mca_btl_openib_proc_create\n", OPAL_PROC_MY_NAME.vpid);
325-
if( NULL != ib_proc ){
326-
OBJ_RELEASE(ib_proc);
327-
}
330+
BTL_ERROR(("%d: error exit from mca_btl_openib_proc_create", OPAL_PROC_MY_NAME.vpid));
331+
332+
OBJ_RELEASE(ib_proc);
328333
return NULL;
329334
}
330335

opal/mca/mpool/hugepage/mpool_hugepage_module.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,15 @@ void *mca_mpool_hugepage_seg_alloc (void *ctx, size_t *sizep)
159159
}
160160

161161
base = mmap (NULL, size, PROT_READ | PROT_WRITE, flags | huge_page->mmap_flags, fd, 0);
162-
close (fd);
163162
if (path) {
164163
unlink (path);
165164
free (path);
166165
}
167166

167+
if (fd >= 0) {
168+
close (fd);
169+
}
170+
168171
if (MAP_FAILED == base) {
169172
opal_output_verbose (MCA_BASE_VERBOSE_WARN, opal_mpool_base_framework.framework_verbose,
170173
"could not allocate huge page(s). falling back on standard pages");

0 commit comments

Comments
 (0)