]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add generic talloc free function for the atexit code
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 12 Jan 2023 21:58:42 +0000 (15:58 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 12 Jan 2023 21:59:18 +0000 (15:59 -0600)
src/lib/util/atexit.h

index eb47c7f410a93b1e74cc7c2f270d7f35056fba96..157e86e71ee1a279ba345b77def31842dd3a3dc8 100644 (file)
@@ -90,8 +90,15 @@ static inline int _fr_atexit_global_once_funcs(fr_atexit_t init_func, fr_atexit_
        return 0;
 }
 
-static inline void fr_atexit_noop(void) {}
-static inline void fr_atexit_result(int *ret, int val) { *ret = val; }
+/** A generic function to free talloc chunks compatible with the fr_atexit_t type
+ *
+ * @param[in] to_free  talloc chunk to free.
+ * @return the return code returned by talloc_free.
+ */
+static inline int fr_atexit_talloc_free(void *to_free)
+{
+       return talloc_free(to_free);
+}
 
 /** Setup pair of global init/free functions, returning errors from the specified init function
  *
@@ -111,6 +118,9 @@ static inline void fr_atexit_result(int *ret, int val) { *ret = val; }
  * @param[in] _free            function to call. Will be called once
  *                             at exit.
  *                             May be NULL.
+ *                             Pass fr_atexit_talloc_free if _uctx is
+ *                             just a talloc chunk and no special logic
+ *                             is needed.
  * @param[in] _uctx            data to be passed to free function.
  */
 #define fr_atexit_global_once_ret(_ret, _init, _free, _uctx) \
@@ -148,6 +158,9 @@ static inline void fr_atexit_result(int *ret, int val) { *ret = val; }
  * @param[in] _free            function to call. Will be called once
  *                             at exit.
  *                             May be NULL.
+ *                             Pass fr_atexit_talloc_free if _uctx is
+ *                             just a talloc chunk and no special logic
+ *                             is needed.
  * @param[in] _uctx            data to be passed to free function.
  */
 #define fr_atexit_global_once(_init, _free, _uctx) \
@@ -161,6 +174,9 @@ static inline void fr_atexit_result(int *ret, int val) { *ret = val; }
  *
  * @param[in] _name            Name of variable e.g. 'my_tls'.
  * @param[in] _free            Destructor, called when the thread exits to clean up any data.
+ *                             Pass fr_atexit_talloc_free if _uctx is
+ *                             just a talloc chunk and no special logic
+ *                             is needed.
  * @param[in] _uctx            Memory to free.
  */
 #  define fr_atexit_thread_local(_name, _free, _uctx) \