[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/11] slirp/misc: Use the GLib memory allocation API
From: |
Michael Tokarev |
Subject: |
[Qemu-devel] [PULL 07/11] slirp/misc: Use the GLib memory allocation APIs |
Date: |
Sun, 24 Aug 2014 17:30:58 +0400 |
From: zhanghailiang <address@hidden>
Here we don't check the return value of malloc() which may fail.
Use the g_new() instead, which will abort the program when
there is not enough memory.
Also, use g_strdup instead of strdup and remove the unnecessary
strdup function.
Signed-off-by: zhanghailiang <address@hidden>
Reviewed-by: Alex Bennée <address@hidden>
Reviewed-by: Benoît Canet <address@hidden>
Signed-off-by: Michael Tokarev <address@hidden>
---
slirp/misc.c | 20 +++-----------------
slirp/misc.h | 4 ----
slirp/slirp_config.h | 3 ---
3 files changed, 3 insertions(+), 24 deletions(-)
diff --git a/slirp/misc.c b/slirp/misc.c
index b8eb74c..6543dc7 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -54,11 +54,11 @@ 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));
+ *ex_ptr = g_new(struct ex_list, 1);
(*ex_ptr)->ex_fport = port;
(*ex_ptr)->ex_addr = addr;
(*ex_ptr)->ex_pty = do_pty;
- (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
+ (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : g_strdup(exec);
(*ex_ptr)->ex_next = tmp_ptr;
return 0;
}
@@ -187,7 +187,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
bptr++;
c = *bptr;
*bptr++ = (char)0;
- argv[i++] = strdup(curarg);
+ argv[i++] = g_strdup(curarg);
} while (c);
argv[i] = NULL;
@@ -228,20 +228,6 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
}
#endif
-#ifndef HAVE_STRDUP
-char *
-strdup(str)
- const char *str;
-{
- char *bptr;
-
- bptr = (char *)malloc(strlen(str)+1);
- strcpy(bptr, str);
-
- return bptr;
-}
-#endif
-
void slirp_connection_info(Slirp *slirp, Monitor *mon)
{
const char * const tcpstates[] = {
diff --git a/slirp/misc.h b/slirp/misc.h
index ba8beb1..41a3258 100644
--- a/slirp/misc.h
+++ b/slirp/misc.h
@@ -16,10 +16,6 @@ struct ex_list {
struct ex_list *ex_next;
};
-#ifndef HAVE_STRDUP
-char *strdup(const char *);
-#endif
-
#define EMU_NONE 0x0
/* TCP emulations */
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 18db45c..896d802 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -72,9 +72,6 @@
/* Define if you have strerror */
#define HAVE_STRERROR
-/* Define if you have strdup() */
-#define HAVE_STRDUP
-
/* Define according to how time.h should be included */
#define TIME_WITH_SYS_TIME 0
#undef HAVE_SYS_TIME_H
--
1.7.10.4
- [Qemu-devel] [PULL 00/11] Trivial patches for 2014-08-24, Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 09/11] linux-user: fix file descriptor leaks, Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 03/11] tests/bios-tables-test: check the value returned by fopen(), Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 06/11] configure: no need to mkdir QMP, Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 02/11] tcg: dump op count into qemu log, Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 10/11] libdecnumber: Fix warnings from smatch (missing static, boolean operations), Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 01/11] util/path: Use the GLib memory allocation routines, Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 07/11] slirp/misc: Use the GLib memory allocation APIs,
Michael Tokarev <=
- [Qemu-devel] [PULL 11/11] vmxnet3: Pad short frames to minimum size (60 bytes), Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 08/11] po: Fix Makefile rules for in-tree builds without configuration, Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 05/11] dma: axidma: Variablise repeated s->streams[i] sub-expr, Michael Tokarev, 2014/08/24
- [Qemu-devel] [PULL 04/11] microblaze: ml605: Get rid of ddr_base variable, Michael Tokarev, 2014/08/24
- Re: [Qemu-devel] [PULL 00/11] Trivial patches for 2014-08-24, Peter Maydell, 2014/08/25