aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-11-21 14:46:55 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2019-11-21 15:32:28 +0400
commit3a494648526be4eb96cba739a816a60e933ffd14 (patch)
tree878b7e916c072d6844bb02f5125102434453cb18
parent61f54d2e4a7ae77065ac2249659c2f1a9a0a2cf5 (diff)
downloadslirp-3a494648526be4eb96cba739a816a60e933ffd14.zip
slirp-3a494648526be4eb96cba739a816a60e933ffd14.tar.gz
slirp-3a494648526be4eb96cba739a816a60e933ffd14.tar.bz2
Replace remaining malloc/free user with glib
glib mem functions are already used in various places. Let's not mix the two, and instead abort on OOM conditions. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
-rw-r--r--src/sbuf.c21
-rw-r--r--src/socket.c2
-rw-r--r--src/tcp_subr.c8
3 files changed, 9 insertions, 22 deletions
diff --git a/src/sbuf.c b/src/sbuf.c
index dc5ec6c..ee29f58 100644
--- a/src/sbuf.c
+++ b/src/sbuf.c
@@ -9,7 +9,7 @@ static void sbappendsb(struct sbuf *sb, struct mbuf *m);
void sbfree(struct sbuf *sb)
{
- free(sb->sb_data);
+ g_free(sb->sb_data);
}
bool sbdrop(struct sbuf *sb, int num)
@@ -37,24 +37,15 @@ void sbreserve(struct sbuf *sb, int size)
if (sb->sb_data) {
/* Already alloced, realloc if necessary */
if (sb->sb_datalen != size) {
- char *new = realloc(sb->sb_data, size);
+ char *new = g_realloc(sb->sb_data, size);
sb->sb_cc = 0;
- if (new) {
- sb->sb_data = sb->sb_wptr = sb->sb_rptr = new;
- sb->sb_datalen = size;
- } else {
- free(sb->sb_data);
- sb->sb_data = sb->sb_wptr = sb->sb_rptr = NULL;
- sb->sb_datalen = 0;
- }
+ sb->sb_data = sb->sb_wptr = sb->sb_rptr = new;
+ sb->sb_datalen = size;
}
} else {
- sb->sb_wptr = sb->sb_rptr = sb->sb_data = (char *)malloc(size);
+ sb->sb_wptr = sb->sb_rptr = sb->sb_data = g_malloc(size);
sb->sb_cc = 0;
- if (sb->sb_wptr)
- sb->sb_datalen = size;
- else
- sb->sb_datalen = 0;
+ sb->sb_datalen = size;
}
}
diff --git a/src/socket.c b/src/socket.c
index 2f20028..b77b53a 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -95,7 +95,7 @@ void sofree(struct socket *so)
remque(so); /* crashes if so is not in a queue */
if (so->so_tcpcb) {
- free(so->so_tcpcb);
+ g_free(so->so_tcpcb);
}
g_free(so);
}
diff --git a/src/tcp_subr.c b/src/tcp_subr.c
index 2e32cb6..e54f8fa 100644
--- a/src/tcp_subr.c
+++ b/src/tcp_subr.c
@@ -255,11 +255,7 @@ struct tcpcb *tcp_newtcpcb(struct socket *so)
{
register struct tcpcb *tp;
- tp = (struct tcpcb *)malloc(sizeof(*tp));
- if (tp == NULL)
- return ((struct tcpcb *)0);
-
- memset((char *)tp, 0, sizeof(struct tcpcb));
+ tp = g_new0(struct tcpcb, 1);
tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp;
/*
* 40: length of IPv4 header (20) + TCP header (20)
@@ -336,7 +332,7 @@ struct tcpcb *tcp_close(struct tcpcb *tp)
remque(tcpiphdr2qlink(tcpiphdr_prev(t)));
m_free(m);
}
- free(tp);
+ g_free(tp);
so->so_tcpcb = NULL;
/* clobber input socket cache if we're closing the cached connection */
if (so == slirp->tcp_last_so)