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<zhang.zhanghaili...@huawei.com>
---
  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




Reply via email to