Add GCharUP, a unique_ptr type that wraps a g_char pointer and has a
deleter that calls g_free. It can be used to provide automatic memory
management of buffers returned by the GLib API.
Change-Id: I9d98be2f972cc008877b55a20eceeb3dce256cdb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8170
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10842
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
uuid.hpp \
vector.hpp \
std-int.hpp \
- read-fixed-len-int.hpp
+ read-fixed-len-int.hpp \
+ glib-up.hpp
--- /dev/null
+/*
+ * Copyright (c) 2022 EfficiOS, inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_GLIB_UP_HPP
+#define BABELTRACE_CPP_COMMON_GLIB_UP_HPP
+
+#include <glib.h>
+#include <memory>
+
+namespace bt2_common {
+namespace internal {
+
+struct GCharDeleter final
+{
+ void operator()(gchar * const p) noexcept
+ {
+ g_free(p);
+ }
+};
+
+} /* namespace internal */
+
+using GCharUP = std::unique_ptr<gchar, internal::GCharDeleter>;
+
+} /* namespace bt2_common */
+
+#endif /* BABELTRACE_CPP_COMMON_GLIB_UP_HPP */