From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFLr8-0003X1-Vz for qemu-devel@nongnu.org; Thu, 07 Aug 2014 07:27:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFLr0-0003GA-JN for qemu-devel@nongnu.org; Thu, 07 Aug 2014 07:27:38 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:41744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFLqz-00038q-Uh for qemu-devel@nongnu.org; Thu, 07 Aug 2014 07:27:30 -0400 Message-ID: <53E36232.7000703@huawei.com> Date: Thu, 7 Aug 2014 19:25:38 +0800 From: zhanghailiang MIME-Version: 1.0 References: <1407398512-20780-1-git-send-email-zhang.zhanghailiang@huawei.com> <1407398512-20780-7-git-send-email-zhang.zhanghailiang@huawei.com> <33183CC9F5247A488A2544077AF1902086C28FFE@SZXEMA503-MBS.china.huawei.com> In-Reply-To: <33183CC9F5247A488A2544077AF1902086C28FFE@SZXEMA503-MBS.china.huawei.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 06/10] slirp: check return value of malloc() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Gonglei (Arei)" Cc: "kwolf@redhat.com" , "lkurusa@redhat.com" , "mst@redhat.com" , "jan.kiszka@siemens.com" , "riku.voipio@iki.fi" , "mjt@tls.msk.ru" , "qemu-devel@nongnu.org" , "Huangpeng (Peter)" , "stefanha@redhat.com" , Luonengjun , "pbonzini@redhat.com" , "lcapitulino@redhat.com" , "alex.bennee@linaro.org" , "rth@twiddle.net" On 2014/8/7 19:08, Gonglei (Arei) wrote: >> Subject: [Qemu-devel] [PATCH v3 06/10] slirp: check return value of malloc() >> >> Signed-off-by: zhanghailiang >> --- >> slirp/misc.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/slirp/misc.c b/slirp/misc.c >> index b8eb74c..0109c9f 100644 >> --- a/slirp/misc.c >> +++ b/slirp/misc.c >> @@ -55,6 +55,9 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char >> *exec, >> >> tmp_ptr = *ex_ptr; >> *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list)); >> + if (!ex_ptr) { >> + return -1; >> + } > > Not (!ex_ptr) but (*ex_ptr == NULL). Sorry, this is my mistake! > BTW, you'd better add more information when malloc memory filed. > Good idea, i will add it. Thanks! > >> (*ex_ptr)->ex_fport = port; >> (*ex_ptr)->ex_addr = addr; >> (*ex_ptr)->ex_pty = do_pty; >> @@ -236,8 +239,9 @@ strdup(str) >> char *bptr; >> >> bptr = (char *)malloc(strlen(str)+1); >> - strcpy(bptr, str); >> - >> + if (bptr) { >> + strcpy(bptr, str); >> + } >> return bptr; >> } >> #endif