[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 38/59] qstring: add qstring_free()
From: |
Paolo Bonzini |
Subject: |
[PULL 38/59] qstring: add qstring_free() |
Date: |
Thu, 23 Jan 2020 14:50:28 +0100 |
From: Marc-André Lureau <address@hidden>
Similar to g_string_free(), optionally return the underlying char*.
Signed-off-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qapi/qmp/qstring.h | 1 +
qobject/qstring.c | 27 ++++++++++++++++++++++-----
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h
index 3e83e3a..e2e356e 100644
--- a/include/qapi/qmp/qstring.h
+++ b/include/qapi/qmp/qstring.h
@@ -33,6 +33,7 @@ void qstring_append_int(QString *qstring, int64_t value);
void qstring_append(QString *qstring, const char *str);
void qstring_append_chr(QString *qstring, int c);
bool qstring_is_equal(const QObject *x, const QObject *y);
+char *qstring_free(QString *qstring, bool return_str);
void qstring_destroy_obj(QObject *obj);
#endif /* QSTRING_H */
diff --git a/qobject/qstring.c b/qobject/qstring.c
index 1c6897d..b66a2c3 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);
}
--
1.8.3.1
- [PULL 28/59] accel: Introduce the current_accel() wrapper, (continued)
- [PULL 28/59] accel: Introduce the current_accel() wrapper, Paolo Bonzini, 2020/01/23
- [PULL 29/59] accel: Replace current_machine->accelerator by current_accel() wrapper, Paolo Bonzini, 2020/01/23
- [PULL 30/59] accel/tcg: Sanitize include path, Paolo Bonzini, 2020/01/23
- [PULL 31/59] object: add extra sanity checks, Paolo Bonzini, 2020/01/23
- [PULL 32/59] qdev: remove duplicated qdev_property_add_static() doc, Paolo Bonzini, 2020/01/23
- [PULL 33/59] qdev: remove extraneous error, Paolo Bonzini, 2020/01/23
- [PULL 34/59] qdev: move helper function to monitor/misc, Paolo Bonzini, 2020/01/23
- [PULL 35/59] object: avoid extra class property key duplication, Paolo Bonzini, 2020/01/23
- [PULL 36/59] object: add class property initializer, Paolo Bonzini, 2020/01/23
- [PULL 37/59] object: make object_class_property_add* return property, Paolo Bonzini, 2020/01/23
- [PULL 38/59] qstring: add qstring_free(),
Paolo Bonzini <=
- [PULL 39/59] object: add object_property_set_default, Paolo Bonzini, 2020/01/23
- [PULL 40/59] object: do not free class properties, Paolo Bonzini, 2020/01/23
- [PULL 41/59] object: check strong flag with &, Paolo Bonzini, 2020/01/23
- [PULL 42/59] object: rename link "child" to "target", Paolo Bonzini, 2020/01/23
- [PULL 43/59] object: add direct link flag, Paolo Bonzini, 2020/01/23
- [PULL 44/59] object: express const link with link property, Paolo Bonzini, 2020/01/23
- [PULL 45/59] object: add object_class_property_add_link(), Paolo Bonzini, 2020/01/23
- [PULL 46/59] object: release all props, Paolo Bonzini, 2020/01/23
- [PULL 47/59] object: return self in object_ref(), Paolo Bonzini, 2020/01/23
- [PULL 49/59] qdev: rename DeviceClass.props, Paolo Bonzini, 2020/01/23