Respect age when freeing thumbnails from clip cache.

Otherwise they could get freed while queued.

Patch by Igor Poretsky

Change-Id: I436b074d81a85cfeb68a07a17320a3c9c0a43e1e
diff --git a/apps/talk.c b/apps/talk.c
index 03da489..fb16e80 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -349,6 +349,7 @@
 {
     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 @@
     {
         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;
+                }
             }
         }
     }