summaryrefslogtreecommitdiffstats
path: root/qobject
diff options
context:
space:
mode:
authorMarc-André Lureau2020-01-10 16:30:22 +0100
committerPaolo Bonzini2020-01-24 20:59:13 +0100
commit164c374b75f87c6765a705c4418ab7005a2d356f (patch)
treea22061845f7977c11c73fd95977b928e96c30a9b /qobject
parentobject: make object_class_property_add* return property (diff)
downloadqemu-164c374b75f87c6765a705c4418ab7005a2d356f.tar.gz
qemu-164c374b75f87c6765a705c4418ab7005a2d356f.tar.xz
qemu-164c374b75f87c6765a705c4418ab7005a2d356f.zip
qstring: add qstring_free()
Similar to g_string_free(), optionally return the underlying char*. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20200110153039.1379601-10-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qobject')
-rw-r--r--qobject/qstring.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/qobject/qstring.c b/qobject/qstring.c
index 1c6897df00..b66a2c35f2 100644
--- a/qobject/qstring.c
+++ b/qobject/qstring.c
@@ -150,15 +150,32 @@ bool qstring_is_equal(const QObject *x, const QObject *y)
}
/**
+ * qstring_free(): Free the memory allocated by a QString object
+ *
+ * Return: if @return_str, return the underlying string, to be
+ * g_free(), otherwise NULL is returned.
+ */
+char *qstring_free(QString *qstring, bool return_str)
+{
+ char *rv = NULL;
+
+ if (return_str) {
+ rv = qstring->string;
+ } else {
+ g_free(qstring->string);
+ }
+
+ g_free(qstring);
+
+ return rv;
+}
+
+/**
* qstring_destroy_obj(): Free all memory allocated by a QString
* object
*/
void qstring_destroy_obj(QObject *obj)
{
- QString *qs;
-
assert(obj != NULL);
- qs = qobject_to(QString, obj);
- g_free(qs->string);
- g_free(qs);
+ qstring_free(qobject_to(QString, obj), FALSE);
}