Received: from eggs.gnu.org ([2001:4830:134:3::10]:49485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFmJL-0008QL-3A for qemu-devel@nongnu.org; Tue, 18 Feb 2014 10:10:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFmJG-000309-9f for qemu-devel@nongnu.org; Tue, 18 Feb 2014 10:10:15 -0500 Received: from afflict.kos.to ([92.243.29.197]:33356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFmJG-0002zs-2J for qemu-devel@nongnu.org; Tue, 18 Feb 2014 10:10:10 -0500 Date: Tue, 18 Feb 2014 17:10:07 +0200 From: Riku Voipio Message-ID: <20140218151007.GA30891@afflict.kos.to> References: <1392663334-8555-1-git-send-email-peter.maydell@linaro.org> <1392663334-8555-5-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1392663334-8555-5-git-send-email-peter.maydell@linaro.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 4/4] linux-user: Fix error handling in target_to_host_semarray() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel@nongnu.org On Mon, Feb 17, 2014 at 06:55:34PM +0000, Peter Maydell wrote: > Fix two issues in error handling in target_to_host_semarray(): > * don't leak the host_array buffer if lock_user fails > * return an error if malloc() fails With this patch I get on ubuntu raring x86_64 (gcc 4.7): In function =E2=80=98target_to_host_semarray=E2=80=99, inlined from =E2=80=98do_semctl=E2=80=99 at /home/voipio/linaro/qemu/= linux-user/syscall.c:2502:17, inlined from =E2=80=98do_syscall=E2=80=99 at /home/voipio/linaro/qemu= /linux-user/syscall.c:6917:13: /home/voipio/linaro/qemu/linux-user/syscall.c:2439:13: error: attempt to = free a non-heap object =E2=80=98array=E2=80=99 [-Werror=3Dfree-nonheap-ob= ject] cc1: all warnings being treated as errors Other patches in the set seem fine so far (still testing) > Signed-off-by: Peter Maydell > --- > linux-user/syscall.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) >=20 > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index bb3e4b1..c92f026 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -2429,10 +2429,15 @@ static inline abi_long target_to_host_semarray(= int semid, unsigned short **host_ > nsems =3D semid_ds.sem_nsems; > =20 > *host_array =3D malloc(nsems*sizeof(unsigned short)); > + if (!*host_array) { > + return -TARGET_ENOMEM; > + } > array =3D lock_user(VERIFY_READ, target_addr, > nsems*sizeof(unsigned short), 1); > - if (!array) > + if (!array) { > + free(host_array); > return -TARGET_EFAULT; > + } > =20 > for(i=3D0; i __get_user((*host_array)[i], &array[i]); > --=20 > 1.8.5 >=20