Changeset 3457

Show
Ignore:
Timestamp:
07/17/08 12:41:39 (3 months ago)
Author:
bricks
Message:

Fixed bugs. A freed schema was not removed from schemas list. Mutex wasn't unlocked.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/opensync/xmlformat/opensync_xmlformat_schema.c

    r3452 r3457  
    2626#include "opensync-xmlformat.h" 
    2727#include "opensync-xmlformat_internals.h" 
     28 
     29static GList *schemas = NULL; 
     30static GStaticMutex schema_mutex = G_STATIC_MUTEX_INIT; 
     31 
     32static void _osync_xmlformat_schema_lock_mutex() { 
     33        g_static_mutex_lock(&schema_mutex); 
     34} 
     35 
     36static void _osync_xmlformat_schema_unlock_mutex() { 
     37        g_static_mutex_unlock(&schema_mutex); 
     38} 
     39 
    2840 
    2941/** 
     
    5668        } 
    5769        osyncschema->objtype = g_strdup(osync_xmlformat_get_objtype(xmlformat)); 
     70 
    5871        char *schemafilepath = g_strdup_printf("%s%c%s%s%s", 
    5972                path ? path : OPENSYNC_SCHEMASDIR, 
     
    109122 
    110123OSyncXMLFormatSchema *osync_xmlformat_schema_get_instance_with_path(OSyncXMLFormat *xmlformat, const char *schemadir, OSyncError **error) { 
    111         static GList *schemas = NULL; 
    112         static GStaticMutex mutex = G_STATIC_MUTEX_INIT; 
    113124        OSyncXMLFormatSchema *osyncschema = NULL; 
    114125        GList * entry; 
     
    120131         
    121132        objtype = osync_xmlformat_get_objtype(xmlformat); 
     133 
    122134        // get mutex 
    123         g_static_mutex_lock(&mutex); 
     135        _osync_xmlformat_schema_lock_mutex(); 
    124136        // find schema for objtype 
    125         for ( entry = schemas; entry != NULL; entry=entry->next) { // should be fast enough for only a few objtypes 
     137        for ( entry = g_list_first(schemas); entry != NULL; entry = g_list_next(entry)) { // should be fast enough for only a few objtypes 
    126138                osyncschema = (OSyncXMLFormatSchema *) entry->data; 
     139                osync_assert(osyncschema->objtype); 
    127140                if (!strcmp(osyncschema->objtype, objtype) ) { 
    128141                        osync_xmlformat_schema_ref(osyncschema); 
    129                         return osyncschema
     142                        goto exit
    130143                } 
    131144                osyncschema = NULL; 
     
    137150                } 
    138151        } 
     152exit: 
    139153        // release mutex 
    140         g_static_mutex_unlock(&mutex); 
     154        _osync_xmlformat_schema_unlock_mutex(); 
    141155        osync_trace(TRACE_EXIT, "%s, (%p)", __func__, osyncschema ); 
    142156        return osyncschema;      
     
    200214 */ 
    201215void osync_xmlformat_schema_unref(OSyncXMLFormatSchema *osyncschema) { 
    202          
     216        GList *entry;    
     217 
    203218        osync_assert(osyncschema); 
    204219 
    205220        if (g_atomic_int_dec_and_test(&(osyncschema->ref_count))) { 
     221                _osync_xmlformat_schema_lock_mutex(); 
     222                int number_schemas = g_list_length(schemas); 
     223                if ( number_schemas == 1 ) { 
     224                        schemas = NULL; 
     225                } 
     226                else { 
     227                        entry = g_list_remove(schemas, osyncschema); 
     228                } 
     229                _osync_xmlformat_schema_unlock_mutex(); 
    206230                xmlSchemaFreeValidCtxt(osyncschema->context); 
    207231                xmlSchemaFree(osyncschema->schema);