Changeset 653 for soft


Ignore:
Timestamp:
Jul 22, 2015, 2:31:34 PM (9 years ago)
Author:
guerin
Message:

fat32: buf descriptor allocation fixes

Don't leak buffer on IOC access failure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_fat32/fat32.c

    r652 r653  
    10171017            if ( pdesc == NULL )      // miss
    10181018            {
    1019                 // allocate one cluster descriptor and one 4K buffer
    1020                 unsigned char* buf = _malloc( 4096 );
    1021                 pdesc              = _malloc( sizeof(fat_cache_desc_t) );
    1022 
    10231019                // get missing cluster index lba
    10241020                unsigned int lba;
     
    10541050                }
    10551051
     1052                // allocate 4K buffer
     1053                void* buf = _malloc( 4096 );
     1054
    10561055                // load one cluster (8 blocks) from block device
    10571056                if ( _fat_ioc_access( 1,         // descheduling
     
    10611060                                      8 ) )
    10621061                {
     1062                    _free( buf );
    10631063                    _printf("\n[FAT ERROR] in _get_buffer_from_cache()"
    10641064                            " : cannot access block device for lba = %x\n", lba );
     
    10661066                }
    10671067
    1068                 // update cache and buffer descriptor
    1069                 node->children[index] = pdesc;
     1068                // allocate buffer descriptor
     1069                pdesc          = _malloc( sizeof(fat_cache_desc_t) );
    10701070                pdesc->lba     = lba;
    10711071                pdesc->buffer  = buf;
    10721072                pdesc->dirty   = 0;
     1073                node->children[index] = pdesc;
    10731074
    10741075#if (GIET_DEBUG_FAT & 1)
     
    12251226    // search the 64-tree cache from top to bottom
    12261227    fat_cache_node_t*  node   = inode->cache;
    1227     unsigned int       level  = inode->levels;
    1228 
    1229     while ( level )
     1228    unsigned int       level;
     1229
     1230    for ( level = inode->levels; level != 0; level-- )
    12301231    {
    12311232        // compute child index
     
    12411242                _exit();
    12421243            }
    1243  
    1244             // allocate a cluster descriptor and a 4K buffer
    1245             pdesc = _malloc( sizeof(fat_cache_desc_t) );
    1246             unsigned char* buffer = _malloc( 4096 );
    12471244
    12481245#if (GIET_DEBUG_FAT & 1)
     
    12521249#endif
    12531250
    1254             // update cache and pdesc
     1251            // allocate buffer descriptor
     1252            pdesc = _malloc( sizeof(fat_cache_desc_t) );
     1253            pdesc->lba     = _cluster_to_lba( cluster );
     1254            pdesc->buffer  = _malloc( 4096 );
     1255            pdesc->dirty   = 1;
    12551256            node->children[index] = pdesc;
    1256             pdesc->lba     = _cluster_to_lba( cluster );
    1257             pdesc->buffer  = buffer;
    1258             pdesc->dirty   = 1;
    1259 
    1260             // prepare next iteration
    1261             level--;
    12621257        }
    12631258        else                      // not last level => children are 64-tree nodes
     
    12731268            // prepare next iteration
    12741269            node  = child;
    1275             level--;
    1276         }
    1277     } // end while
     1270        }
     1271    } // end for
    12781272} // end _allocate_one_buffer
    12791273
Note: See TracChangeset for help on using the changeset viewer.