diff options
| author | Martin Schwenke <martin@meltin.net> | 2012-07-18 15:53:39 +1000 |
|---|---|---|
| committer | Martin Schwenke <martin@meltin.net> | 2012-09-28 17:05:34 +1000 |
| commit | 7660072544566068a4f26e2b9bab7e5c138e98b5 (patch) | |
| tree | 45345eb51981a1d8d3492dd877d263eeed917243 /ctdb/tests/src | |
| parent | e05fc0e7b0cb78ad6e6b0ce5119d93f418886662 (diff) | |
| download | samba-7660072544566068a4f26e2b9bab7e5c138e98b5.tar.gz samba-7660072544566068a4f26e2b9bab7e5c138e98b5.tar.xz samba-7660072544566068a4f26e2b9bab7e5c138e98b5.zip | |
tests: libctdb stubs must copy pointers rather than just returning them
Some code (e.g. NAT gateway code) modifies the returned result so was
modifying the original.
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit a3f15d2828325bbfba5bc5c0a30429e2ce572a44)
Diffstat (limited to 'ctdb/tests/src')
| -rw-r--r-- | ctdb/tests/src/libctdb_test.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/ctdb/tests/src/libctdb_test.c b/ctdb/tests/src/libctdb_test.c index 56c007e8e3..602a7eb3ed 100644 --- a/ctdb/tests/src/libctdb_test.c +++ b/ctdb/tests/src/libctdb_test.c @@ -313,35 +313,45 @@ static bool current_node_is_connected (struct ctdb_connection *ctdb) bool ctdb_getnodemap(struct ctdb_connection *ctdb, uint32_t destnode, struct ctdb_node_map **nodemap) { + size_t n; + if (!current_node_is_connected(ctdb)) { *nodemap = NULL; return false; } - *nodemap = ctdb->nodemap; + n = offsetof(struct ctdb_node_map, nodes) + (ctdb->nodemap->num) * sizeof(struct ctdb_node_and_flags); + *nodemap = (struct ctdb_node_map *) malloc(n); + memcpy(*nodemap, ctdb->nodemap, n); + return true; } void ctdb_free_nodemap(struct ctdb_node_map *nodemap) { - return; + free(nodemap); } bool ctdb_getifaces(struct ctdb_connection *ctdb, uint32_t destnode, struct ctdb_ifaces_list **ifaces) { + size_t n; + if (!current_node_is_connected(ctdb)) { *ifaces = NULL; return false; } - *ifaces = ctdb->ifaces; + n = offsetof(struct ctdb_ifaces_list, ifaces) + (ctdb->ifaces->num) * sizeof(struct ctdb_iface_info); + *ifaces = (struct ctdb_ifaces_list *) malloc(n); + memcpy(*ifaces, ctdb->ifaces, n); + return true; } void ctdb_free_ifaces(struct ctdb_ifaces_list *ifaces) { - return; + free(ifaces); } bool ctdb_getpnn(struct ctdb_connection *ctdb, @@ -387,18 +397,27 @@ bool ctdb_getrecmaster(struct ctdb_connection *ctdb, bool ctdb_getvnnmap(struct ctdb_connection *ctdb, uint32_t destnode, struct ctdb_vnn_map **vnnmap) { + size_t n; + if (!current_node_is_connected(ctdb)) { *vnnmap = NULL; return false; } - *vnnmap = ctdb->vnnmap; + *vnnmap = (struct ctdb_vnn_map *) malloc(sizeof(struct ctdb_vnn_map)); + n = ctdb->vnnmap->size * sizeof(uint32_t); + (*vnnmap)->map = malloc(n); + memcpy((*vnnmap)->map, ctdb->vnnmap->map, n); + (*vnnmap)->generation = ctdb->vnnmap->generation; + (*vnnmap)->size = ctdb->vnnmap->size; + return true; } void ctdb_free_vnnmap(struct ctdb_vnn_map *vnnmap) { - return; + free(vnnmap->map); + free(vnnmap); } bool |
