From: Rusty Russell Date: Thu, 10 Jan 2008 12:28:39 +0000 (+1100) Subject: Preserve errno on talloc_free X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=ec45d0d2bc380e740ad34b2342b3846685a32610;ds=inline Preserve errno on talloc_free --- 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