From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFh2u-0007yV-Oi for qemu-devel@nongnu.org; Mon, 26 Jan 2015 05:37:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YFh2q-00031M-Oz for qemu-devel@nongnu.org; Mon, 26 Jan 2015 05:37:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFh2q-00031F-Hp for qemu-devel@nongnu.org; Mon, 26 Jan 2015 05:37:24 -0500 Date: Mon, 26 Jan 2015 12:37:14 +0200 From: "Michael S. Tsirkin" Message-ID: <20150126103714.GA2697@redhat.com> References: <1421938231-25698-1-git-send-email-imammedo@redhat.com> <1421938231-25698-2-git-send-email-imammedo@redhat.com> <20150123081119.GE26711@redhat.com> <20150123113529.7954abc0@nial.brq.redhat.com> <20150123132424.GA4579@redhat.com> <20150123144030.21142ed1@nial.brq.redhat.com> <20150123135511.GF4579@redhat.com> <20150123185620.604b83ab@nial.brq.redhat.com> <20150124163350.GC6293@redhat.com> <20150126105721.60641e59@nial.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150126105721.60641e59@nial.brq.redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: pbonzini@redhat.com, drjones@redhat.com, claudio.fontana@huawei.com, qemu-devel@nongnu.org, marcel.a@redhat.com > v.s. explicit headache of alloc/free, which doesn't fix > use-after-free anyway and just adds more boiler plate > plus makes code har to read read > > str = aml_alloc(); > aml_string(str, "foo"); > loc0 = aml_alloc(); > aml_local(loc0, 0); > store = aml_alloc(); > aml_store(store, str, loc0); > aml_append(method, store); > aml_free(store); > aml_free(loc0); > aml_free(str); Looks like I wasn't clear. This is what I propose: void aml_add_method(AmlPool *pool, AmlBlob *aml) { AmlBlob *str = aml_alloc(pool); aml_string(str, "foo"); loc0 = aml_alloc(pool); aml_local(loc0, 0); AmlBob *store = aml_alloc(pool); aml_store(store, str, loc0); aml_append(method, store); } So just propagare AmlPool* everywhere, don't free. Then at top level: AmlPool *pool = aml_pool_alloc(); AmlSsdt = aml_add_ssdt(pool, ....); .... aml_pool_free(pool); So from API perspective, this is very close to what you posted, with just two changes: - pass pool parameter everywhere - have an extra alloc/free in only one place. Happy? -- MST