Skip to content

Commit 39715cc

Browse files
committed
opal_free_list: fix strange size check
OPAL free lists can be initialized with a fragment size that differs from the size of objects from a class. This allows the free list code to support OPAL objects that have flexible array members. Unfortunately the free list code will throw out the desired length in some cases. The code in question was committed in open-mpi/ompi@90fb58de. The side effects of this are varied and can cause segmentation faults, assert failures, hangs, etc. This commit adds a check to ensure the requested size is at least as large as the class size and makes opal_free_list allocations always honor the requested fragment size (as long as it is larger than the class size). (cherry picked from open-mpi/ompi@2c02294) Signed-off-by: Nathan Hjelm <[email protected]>
1 parent e0876f4 commit 39715cc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

opal/class/opal_free_list.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ int opal_free_list_init (opal_free_list_t *flist, size_t frag_size, size_t frag_
121121
return OPAL_ERROR;
122122
}
123123

124+
if (frag_class && frag_size < frag_class->cls_sizeof) {
125+
frag_size = frag_class->cls_sizeof;
126+
}
127+
124128
if (frag_size > flist->fl_frag_size) {
125129
flist->fl_frag_size = frag_size;
126130
}
@@ -164,9 +168,7 @@ int opal_free_list_grow_st (opal_free_list_t* flist, size_t num_elements)
164168
return OPAL_ERR_TEMP_OUT_OF_RESOURCE;
165169
}
166170

167-
head_size = (NULL == flist->fl_mpool) ? flist->fl_frag_size:
168-
flist->fl_frag_class->cls_sizeof;
169-
head_size = OPAL_ALIGN(head_size, flist->fl_frag_alignment, size_t);
171+
head_size = OPAL_ALIGN(flist->fl_frag_size, flist->fl_frag_alignment, size_t);
170172

171173
/* calculate head allocation size */
172174
alloc_size = num_elements * head_size + sizeof(opal_free_list_memory_t) +

0 commit comments

Comments
 (0)