Skip to content

Commit 373e816

Browse files
committed
Ensure buffer_unload leaves the buffer in a clean state
Silence a warning in orte/nidmap Signed-off-by: Ralph Castain <[email protected]>
1 parent 73c5fe8 commit 373e816

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

opal/dss/dss_load_unload.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12-
* Copyright (c) 2014-2018 Intel, Inc. All rights reserved.
12+
* Copyright (c) 2014-2019 Intel, Inc. All rights reserved.
1313
* Copyright (c) 2015-2017 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2018 IBM Corporation. All rights reserved.
@@ -57,10 +57,8 @@ int opal_dss_unload(opal_buffer_t *buffer, void **payload,
5757
*payload = buffer->base_ptr;
5858
*bytes_used = buffer->bytes_used;
5959
buffer->base_ptr = NULL;
60-
buffer->unpack_ptr = NULL;
61-
buffer->pack_ptr = NULL;
6260
buffer->bytes_used = 0;
63-
return OPAL_SUCCESS;
61+
goto cleanup;
6462
}
6563

6664
/* okay, we have something to provide - pass it back */
@@ -74,8 +72,10 @@ int opal_dss_unload(opal_buffer_t *buffer, void **payload,
7472
memcpy(*payload, buffer->unpack_ptr, *bytes_used);
7573
}
7674

77-
/* All done */
78-
75+
cleanup:
76+
/* All done - reset the buffer */
77+
OBJ_DESTRUCT(buffer);
78+
OBJ_CONSTRUCT(buffer, opal_buffer_t);
7979
return OPAL_SUCCESS;
8080
}
8181

@@ -89,17 +89,11 @@ int opal_dss_load(opal_buffer_t *buffer, void *payload,
8989
}
9090

9191
/* check if buffer already has payload - free it if so */
92-
if (NULL != buffer->base_ptr) {
93-
free(buffer->base_ptr);
94-
}
92+
OBJ_DESTRUCT(buffer);
93+
OBJ_CONSTRUCT(buffer, opal_buffer_t);
9594

9695
/* if it's a NULL payload, just set things and return */
9796
if (NULL == payload) {
98-
buffer->base_ptr = NULL;
99-
buffer->pack_ptr = buffer->base_ptr;
100-
buffer->unpack_ptr = buffer->base_ptr;
101-
buffer->bytes_used = 0;
102-
buffer->bytes_allocated = 0;
10397
return OPAL_SUCCESS;
10498
}
10599

orte/util/nidmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ int orte_util_pass_node_info(opal_buffer_t *buffer)
603603
} else {
604604
/* mark that this was not compressed */
605605
compressed = false;
606-
bo.bytes = bucket.base_ptr;
606+
bo.bytes = (uint8_t*)bucket.base_ptr;
607607
bo.size = bucket.bytes_used;
608608
}
609609
/* indicate compression */

test/class/opal_tree.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
4+
* Copyright (c) 2019 Intel, Inc. All rights reserved.
45
* $COPYRIGHT$
56
*
67
* Additional copyrights may follow
@@ -214,8 +215,7 @@ int main(int argc, char **argv)
214215
/* serialize tree */
215216
serial_tree = OBJ_NEW(opal_buffer_t);
216217

217-
if (OPAL_SUCCESS == opal_tree_serialize(opal_tree_get_root(&tree),
218-
serial_tree)) {
218+
if (OPAL_SUCCESS == opal_tree_serialize(opal_tree_get_root(&tree), serial_tree)) {
219219
opal_tree_t tmp_tree;
220220
opal_buffer_t *serial2_tree;
221221

@@ -227,29 +227,28 @@ int main(int argc, char **argv)
227227
/* deserialize tree */
228228
opal_tree_deserialize(serial_tree, &(tmp_tree.opal_tree_sentinel));
229229
/* serialize tmp tree */
230-
serial2_tree = OBJ_NEW(opal_buffer_t);
231-
if (OPAL_SUCCESS == opal_tree_serialize(opal_tree_get_root(&tmp_tree),
232-
serial2_tree)) {
233-
void *payload1, *payload2;
234-
int32_t size1, size2;
235-
236-
/* compare new with original serialization */
237-
serial_tree->unpack_ptr = serial_tree->base_ptr;
238-
serial2_tree->unpack_ptr = serial2_tree->unpack_ptr;
239-
opal_dss.unload(serial_tree, &payload1, &size1);
240-
opal_dss.unload(serial2_tree, &payload2, &size2);
241-
if (size1 == size2) {
242-
if (0 == memcmp(payload1, payload2, size1)) {
243-
test_success();
244-
} else {
245-
test_failure(" failed tree deserialization data compare");
246-
}
247-
} else {
248-
test_failure(" failed tree deserialization size compare");
249-
}
250-
} else {
251-
test_failure(" failed tree second pass serialization");
252-
}
230+
serial2_tree = OBJ_NEW(opal_buffer_t);
231+
if (OPAL_SUCCESS == opal_tree_serialize(opal_tree_get_root(&tmp_tree), serial2_tree)) {
232+
void *payload1, *payload2;
233+
int32_t size1, size2;
234+
235+
/* compare new with original serialization */
236+
serial_tree->unpack_ptr = serial_tree->base_ptr;
237+
serial2_tree->unpack_ptr = serial2_tree->unpack_ptr;
238+
opal_dss.unload(serial_tree, &payload1, &size1);
239+
opal_dss.unload(serial2_tree, &payload2, &size2);
240+
if (size1 == size2) {
241+
if (0 == memcmp(payload1, payload2, size1)) {
242+
test_success();
243+
} else {
244+
test_failure(" failed tree deserialization data compare");
245+
}
246+
} else {
247+
test_failure(" failed tree deserialization size compare");
248+
}
249+
} else {
250+
test_failure(" failed tree second pass serialization");
251+
}
253252
} else {
254253
test_failure(" failed tree serialization");
255254
}

0 commit comments

Comments
 (0)