Skip to content

Commit 54383bf

Browse files
TheAssembler1github-actions[bot]jeanbez
authored
Fix segmentation fault of calling PDCobj_create_mpi twice with duplicate object name (#262)
* Validate sucess of PDC_obj_create and PDC_find_id in PDCobj_create_mpi * Committing clang-format changes --------- Co-authored-by: github-actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jean Luca Bez <jlbez@lbl.gov>
1 parent 91914b4 commit 54383bf

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/api/pdc_obj/include/pdc_mpi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* returned by PDCprop_create(PDC_OBJ_CREATE)
4040
* \param rank_id [IN] MPI process rank
4141
*
42-
* \return Object ID on success/Negative on failure
42+
* \return Object ID on success/Zero on failure
4343
*/
4444
pdcid_t PDCobj_create_mpi(pdcid_t cont_id, const char *obj_name, pdcid_t obj_create_prop, int rank_id,
4545
MPI_Comm comm);

src/api/pdc_obj/pdc_mpi.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
pdcid_t
3333
PDCobj_create_mpi(pdcid_t cont_id, const char *obj_name, pdcid_t obj_prop_id, int rank_id, MPI_Comm comm)
3434
{
35-
pdcid_t ret_value = SUCCEED;
36-
struct _pdc_obj_info *p = NULL;
37-
struct _pdc_id_info * id_info = NULL;
35+
struct _pdc_obj_info *p = NULL;
36+
struct _pdc_id_info * id_info = NULL;
3837
int rank;
38+
pdcid_t ret_value;
3939

4040
FUNC_ENTER(NULL);
4141

@@ -46,14 +46,21 @@ PDCobj_create_mpi(pdcid_t cont_id, const char *obj_name, pdcid_t obj_prop_id, in
4646
else
4747
ret_value = PDC_obj_create(cont_id, obj_name, obj_prop_id, PDC_OBJ_LOCAL);
4848

49+
if (ret_value == 0)
50+
PGOTO_ERROR(ret_value, "PDC_obj_create failed");
51+
4952
id_info = PDC_find_id(ret_value);
50-
p = (struct _pdc_obj_info *)(id_info->obj_ptr);
53+
if (id_info == NULL)
54+
PGOTO_ERROR(0, "PDC_find_id failed for object id: %d", ret_value);
55+
56+
p = (struct _pdc_obj_info *)(id_info->obj_ptr);
5157

5258
MPI_Bcast(&(p->obj_info_pub->meta_id), 1, MPI_LONG_LONG, rank_id, comm);
5359
MPI_Bcast(&(p->obj_info_pub->metadata_server_id), 1, MPI_UINT32_T, rank_id, comm);
5460
MPI_Bcast(&(((pdc_metadata_t *)p->metadata)->data_server_id), 1, MPI_UINT32_T, rank_id, comm);
5561
MPI_Bcast(&(((pdc_metadata_t *)p->metadata)->region_partition), 1, MPI_UINT8_T, rank_id, comm);
5662

63+
done:
5764
FUNC_LEAVE(ret_value);
5865
}
5966

src/tests/obj/read_obj.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ main(int argc, char **argv)
157157
if (global_obj <= 0) {
158158
LOG_ERROR("Error creating an object [%s], exit...\n", obj_name);
159159
ret_value = 1;
160+
goto done;
160161
}
161162

162163
offset = (uint64_t *)malloc(sizeof(uint64_t) * ndim);
@@ -293,6 +294,8 @@ main(int argc, char **argv)
293294
LOG_ERROR("Failed to close PDC");
294295
ret_value = 1;
295296
}
297+
298+
done:
296299
#ifdef ENABLE_MPI
297300
MPI_Finalize();
298301
#endif

0 commit comments

Comments
 (0)