[PATCH] don't deref NULL on dfopen failure; plug a FILE-sized leak
Jim Meyering
jim at meyering.net
Mon Sep 27 16:04:14 UTC 2010
>From c058a6ee160dafffd612c1efde0399f18a8b0995 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Mon, 27 Sep 2010 16:57:57 +0200
Subject: [PATCH] don't deref NULL on dfopen failure; plug a FILE-sized leak
* proxy.c (proxy_repl_cons, proxy_repl_prod): Handle fdopen failure
and don't leak a FILE buffer.
---
proxy.c | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/proxy.c b/proxy.c
index ba34b8e..385e9d4 100644
--- a/proxy.c
+++ b/proxy.c
@@ -329,6 +329,11 @@ proxy_repl_prod (void *ctx)
char *myurl;
int chars;
+ if (fp == NULL) {
+ error(0, errno, "%s: fdopen failed", __func__);
+ return NULL;
+ }
+
chars = snprintf(addr,ADDR_SIZE,
"http://%s:%u/%s",proxy_host,proxy_port,item->path);
if (chars >= ADDR_SIZE) {
@@ -369,7 +374,7 @@ proxy_repl_prod (void *ctx)
done:
DPRINTF("%s returning\n",__func__);
/* Closing should signal to the consumer that we're finished. */
- close(item->pipes[1]);
+ fclose(fp);
return NULL;
}
@@ -495,6 +500,11 @@ proxy_repl_cons (void *ctx)
char *myurl;
int chars;
+ if (fp == NULL) {
+ error(0, errno, "%s: fdopen failed", __func__);
+ return THREAD_FAILED;
+ }
+
server = json_array_get(config,item->server);
s_host = json_string_value(json_object_get(server,"host"));
s_port = json_integer_value(json_object_get(server,"port"));
@@ -588,7 +598,7 @@ proxy_repl_cons (void *ctx)
}
DPRINTF("%s returning\n",__func__);
- close(item->pipes[0]);
+ fclose(fp);
meta_got_copy(bucket,key,s_name);
free(myurl);
return NULL;
--
1.7.3.264.g8bb1
More information about the iwhd-devel
mailing list