summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5c4527c)
raw | patch | inline | side by side (parent: 5c4527c)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 3 Jul 2014 16:38:13 +0000 (18:38 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 3 Jul 2014 16:38:13 +0000 (18:38 +0200) |
Ensure that dynamic memory in the destination is freed before copying the new
data. That'll avoid that the caller has to use data_free_datum() first and
destroy previous data even if the copy fails.
data. That'll avoid that the caller has to use data_free_datum() first and
destroy previous data even if the copy fails.
src/core/data.c | patch | blob | history | |
src/core/store.c | patch | blob | history | |
src/include/core/data.h | patch | blob | history |
diff --git a/src/core/data.c b/src/core/data.c
index dc2d0ae8afde4dbb741bc2525444fddad05ed0a8..beba5a7a4006011dc51838d7f7a5bdd57fa9c846 100644 (file)
--- a/src/core/data.c
+++ b/src/core/data.c
break;
}
+ sdb_data_free_datum(dst);
*dst = tmp;
return 0;
} /* sdb_data_copy */
diff --git a/src/core/store.c b/src/core/store.c
index 3885e5064f22931ba4791642108b4eda26aebe85..8b284e77378bba680ead5d0edc8854049305a955 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
if (status >= 0) {
assert(updated_attr);
- sdb_data_free_datum(&ATTR(updated_attr)->value);
- if (sdb_data_copy(&ATTR(updated_attr)->value, value)) {
+ if (sdb_data_copy(&ATTR(updated_attr)->value, value))
status = -1;
- }
}
pthread_rwlock_unlock(&host_lock);
index 879af9087db92d7346fee2109326df55eaf25dfc..d6bf3179eb39ddb4cb6d2c74b36bc4f718216cb0 100644 (file)
--- a/src/include/core/data.h
+++ b/src/include/core/data.h
* Copy the datum stored in 'src' to the memory location pointed to by 'dst'.
* Any dynamic data (strings, binary data) is copied to newly allocated
* memory. Use, for example, sdb_data_free_datum() to free any dynamic memory
- * stored in a datum.
+ * stored in a datum. On error, 'dst' is unchanged. Else, any dynamic memory
+ * in 'dst' will be freed.
*
* Returns:
* - 0 on success