From nobody Mon Feb 9 20:10:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579793940; cv=none; d=zohomail.com; s=zohoarc; b=B3JwcgqaWdgi+bgGYuWtesKjmHSu9hTdpEPNcjyxrrl5Oze9VbdUt3kj8uG2VjChArBFHT1988dy/zjIz7i5/stJXUDfVYeTO2zPFQ84UDF8NO+E4Ks2ZAlnQ0lhv9/51of8i69kYZVTvFz9aU3WQpyxS8wnHBcOoWjcw4+SRj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579793940; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NRtpysghTnIJUNFyZSG4PEwiYVfrrLID8LkUoY/p4CA=; b=g0qiPfVWHpnXv11MKJ4wgRK07rIf0xBvP5beOZNfSTcRhLCRxQIVxFwOx9C/irSUllybMsoOOQjeLmyn25GGgw8ToA+qPyhcN4P6i1ICRG3rdRtfPLOR5AEcs+sfeFkCrMzuh8/MWti/FZZhQfm9oNp6k8iXRSIeL29ZPWp5ouI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579793940253226.19538517806473; Thu, 23 Jan 2020 07:39:00 -0800 (PST) Received: from localhost ([::1]:59590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iueZO-0000hz-QP for importer@patchew.org; Thu, 23 Jan 2020 10:38:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51733) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucrf-0005PJ-BM for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:49:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iucre-0004DU-7e for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:49:43 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:39172) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iucre-0004C9-1Q for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:49:42 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 20so2591772wmj.4 for ; Thu, 23 Jan 2020 05:49:41 -0800 (PST) Received: from 640k.localdomain.com ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id s15sm3073171wrp.4.2020.01.23.05.49.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jan 2020 05:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NRtpysghTnIJUNFyZSG4PEwiYVfrrLID8LkUoY/p4CA=; b=pJxdwXLcMYwvGwGK+WZ4Luv2M8+omtuPsN5RomK2ZvK4SPXCJJvuPeqgGoepbB+r7D 3k7xbIhqKVZfI/UPP5NvhDDI54pdrCpgl6m+2LSCLjdX9+hPwE1AbBdAzxQrurb3D/od CjrUWDcASkp3zlNDyU7c2q+oxJ0oB8fxDlV1ySyMtovqsz5ncVY90ud5nQEVNIKCTl9O WIExG6iRe0gP2XHWVRuh4KFB8/fNnLn6PTlMCe1fsKm37JJMwwvGonktI6Oxe7L2FAIu XGHrYWYFU/CImovOMrMaiyi9padEVAYqypbhGp8F0HxVZy/NPbfNNWh5O3dgbMiKDbVo dUcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NRtpysghTnIJUNFyZSG4PEwiYVfrrLID8LkUoY/p4CA=; b=pgQWnrDUwOXqx8kzBYaprHIQlhGfx7FyMurQF6u+S8BMieDMN62VebREzW5aVEfYBt iRCzto5Ul6gbkzLlFfkI57yYKMyMO6FeAt5xjdzavd/rXgpPn15vLMN12iGzr4RXfP7x DWDyp6WlCB31xw5t32l8PWVrorlPYGd1atMjVfMQdK0OIE7Jknn31UnZSl7sDPYuQ1dS cn73e+ushcswBZdWFCvB13neU5rmrGjfb1/6MOufpPQSj+BSxkHVKCkYLllrH3g69JQu Xvq/W4cNl6bVJSVYbGuHdsjcke3lMtesGR/C0WS/J88bCABvYyK+hzmbOD2u+ydrEgkE WQUw== X-Gm-Message-State: APjAAAUQkFpKzLuZagrqh2rUTvtWxVGaeXneoSlMAJkNiFOyPyY9Keta 67jIvTfXHPzMwD/QH/pmNaS2RnxX X-Google-Smtp-Source: APXvYqzGjKTURVyJHKhzzMNMurSQlSFHTXb6qeCiQEl5C/GBOAVSxYwm78XEsOAIEAZhWHW8s37cRQ== X-Received: by 2002:a7b:cf01:: with SMTP id l1mr4314489wmg.86.1579787380985; Thu, 23 Jan 2020 05:49:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 39/59] qstring: add qstring_free() Date: Thu, 23 Jan 2020 14:48:42 +0100 Message-Id: <1579787342-27146-40-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1579787342-27146-1-git-send-email-pbonzini@redhat.com> References: <1579787342-27146-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32d X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Similar to g_string_free(), optionally return the underlying char*. Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20200110153039.1379601-10-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- 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); =20 #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) } =20 /** + * 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 =3D NULL; + + if (return_str) { + rv =3D 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 !=3D NULL); - qs =3D qobject_to(QString, obj); - g_free(qs->string); - g_free(qs); + qstring_free(qobject_to(QString, obj), FALSE); } --=20 1.8.3.1