From 3d2ab9aec296535c4a7716fc031a6a83c049faa9 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 8 Apr 2015 13:05:10 +0000 Subject: [PATCH] Fix: Handle case realloc() is used as free(). This (hopefully) corrects the usage of realloc() as free(). This patch is part of the series based on Denis Denisov's input. --- src/fserve.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/fserve.c b/src/fserve.c index 5b4dbcfd..7b0c9680 100644 --- a/src/fserve.c +++ b/src/fserve.c @@ -148,14 +148,12 @@ int fserve_client_waiting (void) unsigned int i = 0; /* only rebuild ufds if there are clients added/removed */ - if (client_tree_changed) - { + if (client_tree_changed) { struct pollfd *ufds_new = realloc(ufds, fserve_clients * sizeof(struct pollfd)); /* REVIEW: If we can not allocate new ufds, keep old ones for now. */ - if (ufds_new) { + if (ufds_new || fserve_clients == 0) { ufds = ufds_new; client_tree_changed = 0; - ufds = ufds_new; fclient = active_list; while (fclient) { @@ -167,15 +165,13 @@ int fserve_client_waiting (void) } } } - if (!ufds) - { + + if (!ufds) { thread_spin_lock (&pending_lock); run_fserv = 0; thread_spin_unlock (&pending_lock); return -1; - } - else if (poll(ufds, fserve_clients, 200) > 0) - { + } else if (poll(ufds, fserve_clients, 200) > 0) { /* mark any clients that are ready */ fclient = active_list; for (i=0; i