char *fn;
        int status;
 
+       int i;
+
        argc = rc->values_num + 2;
        argv = (char **) malloc ((argc + 1) * sizeof (char *));
        if (argv == NULL)
        free (argv);
        free (fn);
 
+       for (i = 0; i < rc->values_num; i++)
+               free (rc->values[i]);
+
        free (rc->values);
        rc->values = NULL;
        rc->values_num = 0;
        }
 
        return (0);
-} /* int rrd_update_file */
+} /* int rrd_write_cache_entry */
 
 static void rrd_cache_flush (int timeout)
 {
                        continue;
                }
 
+               /* will free `rc' */
                rrd_write_cache_entry (keys[i], rc);
                sfree (keys[i]); keys[i] = NULL;
-               sfree (rc->values);
-               sfree (rc);
        } /* for (i = 0..keys_num) */
 
        free (keys);
 
        if (cache == NULL)
        {
+               /* will free `rc' */
                rrd_write_cache_entry (filename, rc);
-               free (rc->values);
-               free (rc);
                return (0);
        }