Fixed incorrect memory allocation bug with tagcache.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10023 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2006-05-30 18:13:18 +00:00
parent 62c88c04de
commit 5127cfad1d
2 changed files with 21 additions and 3 deletions

View file

@ -1832,6 +1832,10 @@ static bool commit(void)
int i, len, rc;
int tmpfd;
int masterfd;
#ifdef HAVE_DIRCACHE
bool dircache_buffer_stolen = false;
#endif
bool local_allocation = false;
logf("committing tagcache");
@ -1864,12 +1868,18 @@ static bool commit(void)
}
/* Try to steal every buffer we can :) */
if (tempbuf_size == 0)
local_allocation = true;
#ifdef HAVE_DIRCACHE
if (tempbuf_size == 0)
{
/* Try to steal the dircache buffer. */
tempbuf = dircache_steal_buffer(&tempbuf_size);
tempbuf_size &= ~0x03;
if (tempbuf_size > 0)
dircache_buffer_stolen = true;
}
#endif
@ -1956,8 +1966,15 @@ static bool commit(void)
logf("tagcache committed");
remove(TAGCACHE_FILE_TEMP);
if (local_allocation)
{
tempbuf = NULL;
tempbuf_size = 0;
}
#ifdef HAVE_DIRCACHE
/* Rebuild the dircache, if we stole the buffer. */
if (dircache_buffer_stolen)
dircache_build(0);
#endif

View file

@ -37,13 +37,12 @@
#include "kernel.h"
#include "usb.h"
#include "file.h"
#include "buffer.h"
/* Queue commands. */
#define DIRCACHE_BUILD 1
#define DIRCACHE_STOP 2
extern char *audiobuf;
#define MAX_OPEN_DIRS 8
DIRCACHED opendirs[MAX_OPEN_DIRS];
@ -668,6 +667,8 @@ void dircache_init(void)
{
int i;
dircache_initialized = false;
memset(opendirs, 0, sizeof(opendirs));
for (i = 0; i < MAX_OPEN_DIRS; i++)
{