summaryrefslogtreecommitdiff
path: root/ndb/include/util/UtilBuffer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'ndb/include/util/UtilBuffer.hpp')
-rw-r--r--ndb/include/util/UtilBuffer.hpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/ndb/include/util/UtilBuffer.hpp b/ndb/include/util/UtilBuffer.hpp
index f43fc960a16..ba1f47b93d8 100644
--- a/ndb/include/util/UtilBuffer.hpp
+++ b/ndb/include/util/UtilBuffer.hpp
@@ -73,11 +73,15 @@ public:
}
int assign(const void * d, size_t l) {
- if (data) free(data);
+ /* Free the old data only after copying, in case d==data. */
+ void *old_data= data;
data = NULL;
len = 0;
alloc_size = 0;
- return append(d, l);
+ int ret= append(d, l);
+ if (old_data)
+ free(old_data);
+ return ret;
}
void clear() {