1
1

Ensure buffer_unload leaves the buffer in a clean state

Silence a warning in orte/nidmap

Signed-off-by: Ralph Castain <rhc@pmix.org>
Этот коммит содержится в:
Ralph Castain 2019-09-04 07:51:20 -07:00
родитель 73c5fe8f05
Коммит 373e816b37
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B63B630167D26BB5
3 изменённых файлов: 32 добавлений и 39 удалений

Просмотреть файл

@ -9,7 +9,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2014-2018 Intel, Inc. All rights reserved. * Copyright (c) 2014-2019 Intel, Inc. All rights reserved.
* Copyright (c) 2015-2017 Research Organization for Information Science * Copyright (c) 2015-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* Copyright (c) 2018 IBM Corporation. All rights reserved. * Copyright (c) 2018 IBM Corporation. All rights reserved.
@ -57,10 +57,8 @@ int opal_dss_unload(opal_buffer_t *buffer, void **payload,
*payload = buffer->base_ptr; *payload = buffer->base_ptr;
*bytes_used = buffer->bytes_used; *bytes_used = buffer->bytes_used;
buffer->base_ptr = NULL; buffer->base_ptr = NULL;
buffer->unpack_ptr = NULL;
buffer->pack_ptr = NULL;
buffer->bytes_used = 0; buffer->bytes_used = 0;
return OPAL_SUCCESS; goto cleanup;
} }
/* okay, we have something to provide - pass it back */ /* okay, we have something to provide - pass it back */
@ -74,8 +72,10 @@ int opal_dss_unload(opal_buffer_t *buffer, void **payload,
memcpy(*payload, buffer->unpack_ptr, *bytes_used); memcpy(*payload, buffer->unpack_ptr, *bytes_used);
} }
/* All done */ cleanup:
/* All done - reset the buffer */
OBJ_DESTRUCT(buffer);
OBJ_CONSTRUCT(buffer, opal_buffer_t);
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }
@ -89,17 +89,11 @@ int opal_dss_load(opal_buffer_t *buffer, void *payload,
} }
/* check if buffer already has payload - free it if so */ /* check if buffer already has payload - free it if so */
if (NULL != buffer->base_ptr) { OBJ_DESTRUCT(buffer);
free(buffer->base_ptr); OBJ_CONSTRUCT(buffer, opal_buffer_t);
}
/* if it's a NULL payload, just set things and return */ /* if it's a NULL payload, just set things and return */
if (NULL == payload) { if (NULL == payload) {
buffer->base_ptr = NULL;
buffer->pack_ptr = buffer->base_ptr;
buffer->unpack_ptr = buffer->base_ptr;
buffer->bytes_used = 0;
buffer->bytes_allocated = 0;
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }

Просмотреть файл

@ -603,7 +603,7 @@ int orte_util_pass_node_info(opal_buffer_t *buffer)
} else { } else {
/* mark that this was not compressed */ /* mark that this was not compressed */
compressed = false; compressed = false;
bo.bytes = bucket.base_ptr; bo.bytes = (uint8_t*)bucket.base_ptr;
bo.size = bucket.bytes_used; bo.size = bucket.bytes_used;
} }
/* indicate compression */ /* indicate compression */

Просмотреть файл

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2019 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -214,8 +215,7 @@ int main(int argc, char **argv)
/* serialize tree */ /* serialize tree */
serial_tree = OBJ_NEW(opal_buffer_t); serial_tree = OBJ_NEW(opal_buffer_t);
if (OPAL_SUCCESS == opal_tree_serialize(opal_tree_get_root(&tree), if (OPAL_SUCCESS == opal_tree_serialize(opal_tree_get_root(&tree), serial_tree)) {
serial_tree)) {
opal_tree_t tmp_tree; opal_tree_t tmp_tree;
opal_buffer_t *serial2_tree; opal_buffer_t *serial2_tree;
@ -227,29 +227,28 @@ int main(int argc, char **argv)
/* deserialize tree */ /* deserialize tree */
opal_tree_deserialize(serial_tree, &(tmp_tree.opal_tree_sentinel)); opal_tree_deserialize(serial_tree, &(tmp_tree.opal_tree_sentinel));
/* serialize tmp tree */ /* serialize tmp tree */
serial2_tree = OBJ_NEW(opal_buffer_t); serial2_tree = OBJ_NEW(opal_buffer_t);
if (OPAL_SUCCESS == opal_tree_serialize(opal_tree_get_root(&tmp_tree), if (OPAL_SUCCESS == opal_tree_serialize(opal_tree_get_root(&tmp_tree), serial2_tree)) {
serial2_tree)) { void *payload1, *payload2;
void *payload1, *payload2; int32_t size1, size2;
int32_t size1, size2;
/* compare new with original serialization */ /* compare new with original serialization */
serial_tree->unpack_ptr = serial_tree->base_ptr; serial_tree->unpack_ptr = serial_tree->base_ptr;
serial2_tree->unpack_ptr = serial2_tree->unpack_ptr; serial2_tree->unpack_ptr = serial2_tree->unpack_ptr;
opal_dss.unload(serial_tree, &payload1, &size1); opal_dss.unload(serial_tree, &payload1, &size1);
opal_dss.unload(serial2_tree, &payload2, &size2); opal_dss.unload(serial2_tree, &payload2, &size2);
if (size1 == size2) { if (size1 == size2) {
if (0 == memcmp(payload1, payload2, size1)) { if (0 == memcmp(payload1, payload2, size1)) {
test_success(); test_success();
} else { } else {
test_failure(" failed tree deserialization data compare"); test_failure(" failed tree deserialization data compare");
} }
} else { } else {
test_failure(" failed tree deserialization size compare"); test_failure(" failed tree deserialization size compare");
} }
} else { } else {
test_failure(" failed tree second pass serialization"); test_failure(" failed tree second pass serialization");
} }
} else { } else {
test_failure(" failed tree serialization"); test_failure(" failed tree serialization");
} }