Correct a source of memory leak when --jobs is not explicitly specified.

This commit is contained in:
Ilim Ugur 2012-08-15 02:24:12 +03:00
parent 721697aef6
commit f51826d9d8
3 changed files with 4 additions and 4 deletions

View File

@ -29,14 +29,14 @@ spawn_thread (struct s_thread_ctx *thread_ctx, int index, int resource)
}
int
collect_thread (sem_t *retr_sem, struct s_thread_ctx *thread_ctx)
collect_thread (sem_t *retr_sem, struct s_thread_ctx *thread_ctx, int numthreads)
{
int k, ret;
do
ret = sem_wait (retr_sem);
while (ret < 0 && errno == EINTR);
for (k = 0; k < opt.jobs; k++)
for (k = 0; k < numthreads; k++)
if (thread_ctx[k].used && thread_ctx[k].terminated)
{
url_free (thread_ctx[k].url_parsed);

View File

@ -58,7 +58,7 @@ struct s_thread_ctx
int spawn_thread (struct s_thread_ctx*, int, int);
int collect_thread (sem_t *, struct s_thread_ctx *);
int collect_thread (sem_t *, struct s_thread_ctx *, int);
static void * segmented_retrieve_url (void *);

View File

@ -1168,7 +1168,7 @@ retrieve_from_file (const char *file, bool html, int *count)
while(ranges_covered < N_THREADS)
{
r = collect_thread (&retr_sem, thread_ctx);
r = collect_thread (&retr_sem, thread_ctx, N_THREADS);
++ranges_covered;
status = thread_ctx[r].status;