Skip to content

Commit 554d8dc

Browse files
authored
Merge pull request #679 from DeyanSG/pthread-kill
proc_loadavg: Prevent integer overflow calculating the sleep interval
2 parents 42b57f2 + 2ea5561 commit 554d8dc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/proc_loadavg.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ static void *load_begin(void *arg)
504504
int first_node, sum;
505505
struct load_node *f;
506506
clock_t time1, time2;
507+
int sleep_time;
507508

508509
for (;;) {
509510
if (loadavg_stop == 1)
@@ -542,8 +543,9 @@ static void *load_begin(void *arg)
542543
return NULL;
543544

544545
time2 = clock();
545-
usleep(FLUSH_TIME * 1000000 -
546-
(int)((time2 - time1) * 1000000 / CLOCKS_PER_SEC));
546+
sleep_time = FLUSH_TIME - (int)((time2 - time1) / CLOCKS_PER_SEC);
547+
if ((sleep_time > 0) && (sleep_time <= FLUSH_TIME))
548+
usleep(sleep_time * 1000000);
547549
}
548550
}
549551

0 commit comments

Comments
 (0)