From e6b03ffa823aa2385c989fac9662bfd19679c5de Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sun, 21 Jul 2019 09:03:38 -0400 Subject: Respect age when freeing thumbnails from clip cache. Otherwise they could get freed while queued. Patch by Igor Poretsky Change-Id: I436b074d81a85cfeb68a07a17320a3c9c0a43e1e --- apps/talk.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'apps') diff --git a/apps/talk.c b/apps/talk.c index 03da4897c8..fb16e80417 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -349,6 +349,7 @@ static int free_oldest_clip(void) { unsigned i; int oldest = 0; + bool thumb = false; long age, now; struct clip_entry* clipbuf; struct clip_cache_metadata *cc = buflib_get_data(&clip_ctx, metadata_table_handle); @@ -356,17 +357,26 @@ static int free_oldest_clip(void) { if (cc[i].handle) { - if ((now - cc[i].tick) > age && cc[i].voice_id != VOICE_PAUSE) + if (thumb && cc[i].voice_id == VOICEONLY_DELIMITER && (now - cc[i].tick) > age) { - /* find the last-used clip but never consider silence */ + /* thumb clips are freed first */ age = now - cc[i].tick; oldest = i; } - else if (cc[i].voice_id == VOICEONLY_DELIMITER) + else if (!thumb) { - /* thumb clips are freed immediately */ - oldest = i; - break; + if (cc[i].voice_id == VOICEONLY_DELIMITER) + { + age = now - cc[i].tick; + oldest = i; + thumb = true; + } + else if ((now - cc[i].tick) > age && cc[i].voice_id != VOICE_PAUSE) + { + /* find the last-used clip but never consider silence */ + age = now - cc[i].tick; + oldest = i; + } } } } -- cgit v1.2.3