From de77386d84f8d9237020bc5d12ef51b754cb7563 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Sun, 17 Jul 2011 17:48:17 +0200 Subject: server: Fix memory leak and error handling in restart_pcap --- src/osmo_server_network.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/osmo_server_network.c b/src/osmo_server_network.c index 121aa2c..be61d03 100644 --- a/src/osmo_server_network.c +++ b/src/osmo_server_network.c @@ -62,14 +62,20 @@ static void restart_pcap(struct osmo_pcap_conn *conn) conn->local_fd = -1; } - filename = talloc_asprintf(conn, "%s/trace-%s-%d%.2d%.2d_%.2d%.2d%.2d.pcap", conn->server->base_path, conn->name, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); + + if (!filename) { + LOGP(DSERVER, LOGL_ERROR, "Failed to assemble filename for %s.\n", conn->name); + return; + } + conn->local_fd = creat(filename, 0440); if (conn->local_fd < 0) { LOGP(DSERVER, LOGL_ERROR, "Failed to file: '%s'\n", filename); + talloc_free(filename); return; } @@ -78,6 +84,7 @@ static void restart_pcap(struct osmo_pcap_conn *conn) LOGP(DSERVER, LOGL_ERROR, "Failed to write the header: %d\n", errno); close(conn->local_fd); conn->local_fd = -1; + talloc_free(filename); return; } -- cgit v1.2.3