Skip to content

Commit

Permalink
server: Never set lastTime=0 for leaky buckets as it may cause leaking
Browse files Browse the repository at this point in the history
of leaky buckets :p refs #541
  • Loading branch information
ec- authored and IR4T4 committed Feb 4, 2018
1 parent 850f9c7 commit 8120de3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/server/sv_main.c
Expand Up @@ -623,6 +623,9 @@ static leakyBucket_t *SVC_BucketForAddress(netadr_t address, int burst, int peri
}
}

// make sure we will never use time 0
now = now ? now : 1;

for (i = 0; i < MAX_BUCKETS; i++)
{
int interval;
Expand All @@ -631,7 +634,7 @@ static leakyBucket_t *SVC_BucketForAddress(netadr_t address, int burst, int peri
interval = now - bucket->lastTime;

// Reclaim expired buckets
if (bucket->lastTime > 0 && (interval > (burst * period) || interval < 0))
if (bucket->lastTime > 0 && (unsigned) interval > (burst * period))
{
if (bucket->prev != NULL)
{
Expand Down

0 comments on commit 8120de3

Please sign in to comment.