1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/apps/scrobbler.c b/apps/scrobbler.c
index 891e635..077b4ee 100644
--- a/apps/scrobbler.c
+++ b/apps/scrobbler.c
@@ -140,10 +140,14 @@ static void write_cache(void)
     {
         logf("SCROBBLER: writing %d entries", cache_pos); 
         char* scrobbler_buf = core_get_data(scrobbler_cache);
+        /* copy data to temporary storage in case data moves during I/O */
+        char temp_buf[SCROBBLER_CACHE_LEN];
         for ( i=0; i < cache_pos; i++ )
         {
             logf("SCROBBLER: write %d", i);
-            fdprintf(fd, "%s", scrobbler_buf+(SCROBBLER_CACHE_LEN*i));
+            size_t len = strlcpy(temp_buf, scrobbler_buf+(SCROBBLER_CACHE_LEN*i));
+            if (write(fd, temp_buf, len) != len)
+                break;
         }
         close(fd);
     }