Index: /soft/giet_vm/giet_fat32/fat32.c
===================================================================
--- /soft/giet_vm/giet_fat32/fat32.c	(revision 652)
+++ /soft/giet_vm/giet_fat32/fat32.c	(revision 653)
@@ -1017,8 +1017,4 @@
             if ( pdesc == NULL )      // miss 
             {
-                // allocate one cluster descriptor and one 4K buffer
-                unsigned char* buf = _malloc( 4096 );
-                pdesc              = _malloc( sizeof(fat_cache_desc_t) );
-
                 // get missing cluster index lba
                 unsigned int lba;
@@ -1054,4 +1050,7 @@
                 }
 
+                // allocate 4K buffer
+                void* buf = _malloc( 4096 );
+
                 // load one cluster (8 blocks) from block device
                 if ( _fat_ioc_access( 1,         // descheduling
@@ -1061,4 +1060,5 @@
                                       8 ) )
                 {
+                    _free( buf );
                     _printf("\n[FAT ERROR] in _get_buffer_from_cache()"
                             " : cannot access block device for lba = %x\n", lba );
@@ -1066,9 +1066,10 @@
                 }
 
-                // update cache and buffer descriptor
-                node->children[index] = pdesc;
+                // allocate buffer descriptor
+                pdesc          = _malloc( sizeof(fat_cache_desc_t) );
                 pdesc->lba     = lba;
                 pdesc->buffer  = buf;
                 pdesc->dirty   = 0;
+                node->children[index] = pdesc;
 
 #if (GIET_DEBUG_FAT & 1)
@@ -1225,7 +1226,7 @@
     // search the 64-tree cache from top to bottom 
     fat_cache_node_t*  node   = inode->cache;
-    unsigned int       level  = inode->levels;
-
-    while ( level )
+    unsigned int       level;
+
+    for ( level = inode->levels; level != 0; level-- )
     {
         // compute child index
@@ -1241,8 +1242,4 @@
                 _exit();
             }
- 
-            // allocate a cluster descriptor and a 4K buffer
-            pdesc = _malloc( sizeof(fat_cache_desc_t) );
-            unsigned char* buffer = _malloc( 4096 );
 
 #if (GIET_DEBUG_FAT & 1)
@@ -1252,12 +1249,10 @@
 #endif
 
-            // update cache and pdesc
+            // allocate buffer descriptor
+            pdesc = _malloc( sizeof(fat_cache_desc_t) );
+            pdesc->lba     = _cluster_to_lba( cluster );
+            pdesc->buffer  = _malloc( 4096 );
+            pdesc->dirty   = 1;
             node->children[index] = pdesc;
-            pdesc->lba     = _cluster_to_lba( cluster );
-            pdesc->buffer  = buffer;
-            pdesc->dirty   = 1;
-
-            // prepare next iteration
-            level--;
         }
         else                      // not last level => children are 64-tree nodes
@@ -1273,7 +1268,6 @@
             // prepare next iteration
             node  = child;
-            level--;
-        }
-    } // end while
+        }
+    } // end for
 } // end _allocate_one_buffer
 
