From ec45d0d2bc380e740ad34b2342b3846685a32610 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 10 Jan 2008 23:28:39 +1100 Subject: [PATCH] Preserve errno on talloc_free --- talloc/talloc.c | 6 +++++- talloc/talloc.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/talloc/talloc.c b/talloc/talloc.c index 17bb0ec8..e9f531fe 100644 --- a/talloc/talloc.c +++ b/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) { - return _talloc_free(ptr); + int saved_errno = errno, ret; + ret = _talloc_free(ptr); + if (ret == 0) + errno = saved_errno; + return ret; } diff --git a/talloc/talloc.h b/talloc/talloc.h index f79f45b2..510cff75 100644 --- a/talloc/talloc.h +++ b/talloc/talloc.h @@ -100,6 +100,7 @@ * 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 * 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 * the memory is not actually released, but instead the most recently -- 2.39.2