Skip to content

Commit 5884d38

Browse files
committed
opal: fix various coverity errors
Fix CID 1356358: Null pointer dereferences (REVERSE_INULL): flist->fl_mpool can no longer be NULL. Removed the conditional. Fix CID 1356357: Resource leaks (RESOURCE_LEAK): Added the call to free the hints array. Fix CID 1356356: Resource leaks (RESOURCE_LEAK): This is a false error but it is safe to call close (-1) so just always call close. Fix CID 1356354: Control flow issues (MISSING_BREAK): Fix CID 1356353: Control flow issues (MISSING_BREAK): Add comments that indicate the fall-through is intentional. Fix CID 1356351: Null pointer dereferences (FORWARD_NULL): Fix potential SEGV if the page_size key is malformed. Fix CID 1356350: Error handling issues (CHECKED_RETURN): Add (void) to indicate that we do not care about the return code of sscanf in this case. Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 9bb1d00 commit 5884d38

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

opal/class/opal_free_list.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements)
225225
flist->fl_rcache_reg_flags, MCA_RCACHE_ACCESS_ANY, &reg);
226226
if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) {
227227
free (alloc_ptr);
228-
if (flist->fl_mpool) {
229-
flist->fl_mpool->mpool_free (flist->fl_mpool, payload_ptr);
230-
} else {
231-
free (payload_ptr);
232-
}
228+
flist->fl_mpool->mpool_free (flist->fl_mpool, payload_ptr);
233229

234230
return rc;
235231
}

opal/mca/mpool/hugepage/mpool_hugepage_component.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static void mca_mpool_hugepage_find_hugepages (void) {
227227
page_size = info.f_bsize;
228228
#endif
229229
} else {
230-
sscanf (tok, "pagesize=%lu", &page_size);
230+
(void) sscanf (tok, "pagesize=%lu", &page_size);
231231
}
232232

233233
if (0 == page_size) {
@@ -294,20 +294,23 @@ static int mca_mpool_hugepage_query (const char *hints, int *priority_out,
294294
my_priority = 0;
295295
opal_output_verbose (MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output,
296296
"hugepage mpool does not match hint: %s=%s", key, value);
297+
opal_argv_free (hints_array);
297298
return OPAL_ERR_NOT_FOUND;
298299
}
299300
}
300301

301-
if (0 == strcasecmp ("page_size", key)) {
302+
if (0 == strcasecmp ("page_size", key) && value) {
302303
page_size = strtoul (value, &tmp, 0);
303304
if (*tmp) {
304305
switch (*tmp) {
305306
case 'g':
306307
case 'G':
307308
page_size *= 1024;
309+
/* fall through */
308310
case 'm':
309311
case 'M':
310312
page_size *= 1024;
313+
/* fall through */
311314
case 'k':
312315
case 'K':
313316
page_size *= 1024;

opal/mca/mpool/hugepage/mpool_hugepage_module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 2006 Voltaire. All rights reserved.
1515
* Copyright (c) 2007 Mellanox Technologies. All rights reserved.
1616
* Copyright (c) 2010 IBM Corporation. All rights reserved.
17-
* Copyright (c) 2011-2015 Los Alamos National Security, LLC. All rights
17+
* Copyright (c) 2011-2016 Los Alamos National Security, LLC. All rights
1818
* reserved.
1919
*
2020
* $COPYRIGHT$
@@ -159,8 +159,8 @@ 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);
162163
if (path) {
163-
close (fd);
164164
unlink (path);
165165
free (path);
166166
}

0 commit comments

Comments
 (0)