upas/fs: fix infinite loop in putcache (again)

The previous attempt to fix this problem (see changesets b32199e0f90a
and 00ae79a6ba50) caused all calls to cachefree to free the cached
message contents in addition to updating the LRU list.  This causes
problems for the POP3 driver since it provides no fetch function; once
a message is evicted from the LRU cache, its contents is lost.

This time we fix cachefree to always update the LRU list but only free
the cached message contents if the driver provides a fetch function or
the force flag is set.
This commit is contained in:
Alex Musolino 2018-12-31 00:00:09 +10:30
parent f464b7ff16
commit 2c6cc12133
3 changed files with 7 additions and 5 deletions

View file

@ -35,7 +35,7 @@ notecache(Mailbox *mb, Message *m, long sz)
}
void
cachefree(Mailbox *mb, Message *m)
cachefree(Mailbox *mb, Message *m, int force)
{
long i;
Message *s, **ll;
@ -54,7 +54,9 @@ cachefree(Mailbox *mb, Message *m)
mb->cached -= m->csize;
}
for(s = m->part; s; s = s->next)
cachefree(mb, s);
cachefree(mb, s, force);
if(!force && mb->fetch == nil)
return;
if(m->mallocd){
free(m->start);
m->mallocd = 0;
@ -101,7 +103,7 @@ putcache(Mailbox *mb, Message *m)
return;
addlru(mb, mb->lru);
}
cachefree(mb, mb->lru);
cachefree(mb, mb->lru, 0);
}
}

View file

@ -207,7 +207,7 @@ int insurecache(Mailbox*, Message*);
/**/
void putcache(Mailbox*, Message*); /* asymmetricial */
void cachefree(Mailbox*, Message*);
void cachefree(Mailbox*, Message*, int);
char* syncmbox(Mailbox*, int);
void* emalloc(ulong);

View file

@ -1041,7 +1041,7 @@ delmessage(Mailbox *mb, Message *m)
if(Topmsg(mb, m))
mtreedelete(mb, m);
cachefree(mb, m);
cachefree(mb, m, 1);
idxfree(m);
}
free(m->unixfrom);