Browse Source

Preserve errno on talloc_free

Rusty Russell 18 years ago
parent
commit
ec45d0d2bc
2 changed files with 6 additions and 1 deletions
  1. 5 1
      talloc/talloc.c
  2. 1 0
      talloc/talloc.h

+ 5 - 1
talloc/talloc.c

@@ -730,7 +730,11 @@ void *talloc_named_const(const void *context, size_t size, const char *name)
 */
 */
 int talloc_free(void *ptr)
 int talloc_free(void *ptr)
 {
 {
-	return _talloc_free(ptr);
+	int saved_errno = errno, ret;
+	ret = _talloc_free(ptr);
+	if (ret == 0)
+		errno = saved_errno;
+	return ret;
 }
 }
 
 
 
 

+ 1 - 0
talloc/talloc.h

@@ -100,6 +100,7 @@
  * returned for success and -1 for failure. The only possible failure condition
  * returned for success and -1 for failure. The only possible failure condition
  * is if the pointer had a destructor attached to it and the destructor
  * is if the pointer had a destructor attached to it and the destructor
  * returned -1. See talloc_set_destructor() for details on destructors.
  * returned -1. See talloc_set_destructor() for details on destructors.
+ * errno will be preserved unless the talloc_free fails.
  *
  *
  * If this pointer has an additional parent when talloc_free() is called then
  * If this pointer has an additional parent when talloc_free() is called then
  * the memory is not actually released, but instead the most recently
  * the memory is not actually released, but instead the most recently