Skip to content

Commit

Permalink
Fix: Handle case realloc() is used as free().
Browse files Browse the repository at this point in the history
This (hopefully) corrects the usage of realloc() as free().
This patch is part of the series based on Denis Denisov's input.
  • Loading branch information
ph3-der-loewe committed Apr 8, 2015
1 parent 6605f4d commit 3d2ab9a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/fserve.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<fserve_clients; i++)
Expand All @@ -186,6 +182,7 @@ int fserve_client_waiting (void)
}
return 1;
}

return 0;
}
#else
Expand Down

0 comments on commit 3d2ab9a

Please sign in to comment.