mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
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>
This commit is contained in:
parent
a3a162113e
commit
164c374b75
2 changed files with 23 additions and 5 deletions
|
@ -149,16 +149,33 @@ bool qstring_is_equal(const QObject *x, const QObject *y)
|
|||
qobject_to(QString, y)->string);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue