]> git.sesse.net Git - mlt/blobdiff - src/modules/xml/producer_xml.c
fix leak on allocated sax context
[mlt] / src / modules / xml / producer_xml.c
index 2baec97d11b042ece5bfca8f63ca3e369fe99eb0..19160a267b73fefd600ee0f6066f2dd84c1ebe77 100644 (file)
@@ -160,8 +160,11 @@ static mlt_service context_pop_service( deserialise_context context, enum servic
                if ( type != NULL )
                        *type = context->stack_types[ context->stack_service_size ];
                // Set the service's profile and locale so mlt_property time-to-position conversions can get fps
-               mlt_properties_set_data( MLT_SERVICE_PROPERTIES( result ), "_profile", context->profile, 0, NULL, NULL );
-               mlt_properties_set_lcnumeric( MLT_SERVICE_PROPERTIES( result ), context->lc_numeric );
+               if ( result )
+               {
+                       mlt_properties_set_data( MLT_SERVICE_PROPERTIES( result ), "_profile", context->profile, 0, NULL, NULL );
+                       mlt_properties_set_lcnumeric( MLT_SERVICE_PROPERTIES( result ), context->lc_numeric );
+               }
        }
        return result;
 }
@@ -1532,7 +1535,7 @@ static int file_exists( char *file )
 
 mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype, const char *id, char *data )
 {
-       xmlSAXHandler *sax;
+       xmlSAXHandler *sax, *sax_orig;
        struct deserialise_context_s *context;
        mlt_properties properties = NULL;
        int i = 0;
@@ -1619,14 +1622,17 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
        }
 
        // Parse
+       sax_orig = xmlcontext->sax;
        xmlcontext->sax = sax;
        xmlcontext->_private = ( void* )context;        
        xmlParseDocument( xmlcontext );
        well_formed = xmlcontext->wellFormed;
        
        // Cleanup after parsing
-       xmlcontext->sax = NULL;
+       xmlcontext->sax = sax_orig;
        xmlcontext->_private = NULL;
+       if ( xmlcontext->myDoc )
+               xmlFreeDoc( xmlcontext->myDoc );
        xmlFreeParserCtxt( xmlcontext );
        context->stack_node_size = 0;
        context->stack_service_size = 0;
@@ -1673,6 +1679,7 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
        sax->getEntity = on_get_entity;
 
        // Parse
+       sax_orig = xmlcontext->sax;
        xmlcontext->sax = sax;
        xmlcontext->_private = ( void* )context;
        xmlParseDocument( xmlcontext );
@@ -1682,6 +1689,11 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
        xmlFreeDoc( context->entity_doc );
        free( sax );
        xmlMemoryDump( ); // for debugging
+       xmlcontext->sax = sax_orig;
+       xmlcontext->_private = NULL;
+       if ( xmlcontext->myDoc )
+               xmlFreeDoc( xmlcontext->myDoc );
+       xmlFreeParserCtxt( xmlcontext );
 
        // Get the last producer on the stack
        enum service_type type;
@@ -1734,8 +1746,17 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
                if ( getenv( "MLT_XML_DEEP" ) == NULL )
                {
                        // Now assign additional properties
-                       if ( is_filename && mlt_service_identify( service ) == tractor_type )
+                       if ( is_filename && (
+                               mlt_service_identify( service ) == tractor_type ||
+                               mlt_service_identify( service ) == playlist_type ||
+                               mlt_service_identify( service ) == multitrack_type ) )
+                       {
+                               mlt_properties_set_int( properties, "_original_type",
+                                       mlt_service_identify( service ) );
+                               mlt_properties_set( properties, "_original_resource",
+                                       mlt_properties_get( properties, "resource" ) );
                                mlt_properties_set( properties, "resource", data );
+                       }
 
                        // This tells consumer_xml not to deep copy
                        mlt_properties_set( properties, "xml", "was here" );