[webkit-changes] cvs commit: WebCore/khtml/xsl xslt_processorimpl.cpp xslt_processorimpl.h

Eric eseidel at opensource.apple.com
Mon Oct 10 16:48:56 PDT 2005


eseidel     05/10/10 16:48:56

  Modified:    .        ChangeLog
               khtml/xml dom_docimpl.cpp xml_tokenizer.cpp
               khtml/xsl xslt_processorimpl.cpp xslt_processorimpl.h
  Log:
  Bug #: 5320
  Submitted by: darin
  Reviewed by: eseidel
          Mem leak fixes in xslt code.
          http://bugzilla.opendarwin.org/show_bug.cgi?id=5320
  
          * khtml/xml/dom_docimpl.cpp:
          (DocumentImpl::applyXSLTransform):
          (DocumentImpl::setTransformSourceDocument):
          * khtml/xml/xml_tokenizer.cpp:
          (khtml::parseXMLDocumentFragment):
          * khtml/xsl/xslt_processorimpl.cpp:
          (DOM::XSLTProcessorImpl::XSLTProcessorImpl):
          (DOM::XSLTProcessorImpl::~XSLTProcessorImpl):
          (DOM::stylesheetLoadFunc):
          (DOM::XSLTProcessorImpl::transformDocument):
          (DOM::XSLTProcessorImpl::documentFromXMLDocPtr):
          * khtml/xsl/xslt_processorimpl.h:
          (DOM::XSLTProcessorImpl::stylesheet):
          (DOM::XSLTProcessorImpl::sourceDocument):
  
  Revision  Changes    Path
  1.227     +22 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.226
  retrieving revision 1.227
  diff -u -r1.226 -r1.227
  --- ChangeLog	10 Oct 2005 03:50:20 -0000	1.226
  +++ ChangeLog	10 Oct 2005 23:48:48 -0000	1.227
  @@ -1,3 +1,25 @@
  +2005-10-10  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by eseidel.
  +
  +        Mem leak fixes in xslt code.
  +        http://bugzilla.opendarwin.org/show_bug.cgi?id=5320
  +
  +        * khtml/xml/dom_docimpl.cpp:
  +        (DocumentImpl::applyXSLTransform):
  +        (DocumentImpl::setTransformSourceDocument):
  +        * khtml/xml/xml_tokenizer.cpp:
  +        (khtml::parseXMLDocumentFragment):
  +        * khtml/xsl/xslt_processorimpl.cpp:
  +        (DOM::XSLTProcessorImpl::XSLTProcessorImpl):
  +        (DOM::XSLTProcessorImpl::~XSLTProcessorImpl):
  +        (DOM::stylesheetLoadFunc):
  +        (DOM::XSLTProcessorImpl::transformDocument):
  +        (DOM::XSLTProcessorImpl::documentFromXMLDocPtr):
  +        * khtml/xsl/xslt_processorimpl.h:
  +        (DOM::XSLTProcessorImpl::stylesheet):
  +        (DOM::XSLTProcessorImpl::sourceDocument):
  +
   2005-10-09  David Hyatt  <hyatt at apple.com>
   
   	Land fix for bugzilla bug 4974, make sure to only move below floats in line layout if white-space is normal.
  
  
  
  1.260     +6 -6      WebCore/khtml/xml/dom_docimpl.cpp
  
  Index: dom_docimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.cpp,v
  retrieving revision 1.259
  retrieving revision 1.260
  diff -u -r1.259 -r1.260
  --- dom_docimpl.cpp	6 Oct 2005 00:54:05 -0000	1.259
  +++ dom_docimpl.cpp	10 Oct 2005 23:48:53 -0000	1.260
  @@ -3020,23 +3020,23 @@
   }
   
   #ifdef KHTML_XSLT
  +
   void DocumentImpl::applyXSLTransform(ProcessingInstructionImpl* pi)
   {
  -    // Ref ourselves to keep from being destroyed.
  +    // FIXME: Be sure to change this next line to use a SharedPtr instead of a stack-allocated
  +    // object once XSLTProcessorImpl gets a ref count.
       XSLTProcessorImpl processor(static_cast<XSLStyleSheetImpl*>(pi->sheet()), this);
       processor.transformDocument(this);
  -
  -    // FIXME: If the transform failed we should probably report an error (like Mozilla does) in this
  -    // case.
  +    // FIXME: If the transform failed we should probably report an error (like Mozilla does).
   }
   
   void DocumentImpl::setTransformSourceDocument(DocumentImpl* doc)
   { 
  +    if (doc)
  +        doc->ref();
       if (m_transformSourceDocument)
           m_transformSourceDocument->deref(); 
       m_transformSourceDocument = doc;
  -    if (doc)
  -        doc->ref();
   }
   
   #endif
  
  
  
  1.45      +1 -0      WebCore/khtml/xml/xml_tokenizer.cpp
  
  Index: xml_tokenizer.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/xml_tokenizer.cpp,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- xml_tokenizer.cpp	3 Oct 2005 21:12:54 -0000	1.44
  +++ xml_tokenizer.cpp	10 Oct 2005 23:48:54 -0000	1.45
  @@ -839,6 +839,7 @@
       int result = parseQString(parser, string.qstring());
       if (parser->myDoc)
           xmlFreeDoc(parser->myDoc);
  +    xmlFreeParserCtxt(parser);
   
       return result == 0;
   }
  
  
  
  1.13      +14 -20    WebCore/khtml/xsl/xslt_processorimpl.cpp
  
  Index: xslt_processorimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- xslt_processorimpl.cpp	3 Oct 2005 21:12:59 -0000	1.12
  +++ xslt_processorimpl.cpp	10 Oct 2005 23:48:55 -0000	1.13
  @@ -42,20 +42,12 @@
   namespace DOM {
       
   XSLTProcessorImpl::XSLTProcessorImpl(XSLStyleSheetImpl* sheet, DocumentImpl* source)
  -:m_stylesheet(sheet), m_sourceDocument(source)
  +    : m_stylesheet(sheet), m_sourceDocument(source)
   {
  -    if (m_stylesheet)
  -        m_stylesheet->ref();
  -    if (m_sourceDocument)
  -        m_sourceDocument->ref();
   }
   
   XSLTProcessorImpl::~XSLTProcessorImpl()
   {
  -    if (m_stylesheet)
  -        m_stylesheet->deref();
  -    if (m_sourceDocument)
  -        m_sourceDocument->deref();
   }
   
   static void parseErrorFunc(void *ctxt, const char *msg, ...)
  @@ -71,7 +63,7 @@
                                       xsltLoadType type)
   {
       if (!globalProcessor)
  -        return NULL;
  +        return 0;
       
       switch (type) {
           case XSLT_LOAD_DOCUMENT: {
  @@ -100,10 +92,10 @@
               break;
       }
       
  -    return NULL;
  +    return 0;
   }
   
  -DocumentImpl* XSLTProcessorImpl::transformDocument(DocumentImpl* doc)
  +SharedPtr<DocumentImpl> XSLTProcessorImpl::transformDocument(DocumentImpl* doc)
   {
       // FIXME: Right now we assume |doc| is unparsed, but if it has been parsed we will need to serialize it
       // and then feed that resulting source to libxslt.
  @@ -126,13 +118,15 @@
     
       // Get the parsed source document.
       xmlDocPtr sourceDoc = (xmlDocPtr)doc->transformSource();
  -    xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, NULL);
  +    xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, 0);
       
       globalProcessor = 0;
       xsltSetLoaderFunc(0);
   
  -    DocumentImpl* result = documentFromXMLDocPtr(resultDoc, sheet);
  +    SharedPtr<DocumentImpl> result = documentFromXMLDocPtr(resultDoc, sheet);
       xsltFreeStylesheet(sheet);
  +    xmlFreeDoc(resultDoc);
  +
       return result;
   }
   
  @@ -147,13 +141,13 @@
       m_resultOutput += QString::fromUtf8(buffer, len);
   }
   
  -DocumentImpl *XSLTProcessorImpl::documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
  +SharedPtr<DocumentImpl> XSLTProcessorImpl::documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
   {
       if (!resultDoc || !sheet)
           return 0;
   
  -    DocumentImpl *result = 0;
  -    xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(NULL);
  +    SharedPtr<DocumentImpl> result;
  +    xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0);
       if (outputBuf) {
           outputBuf->context = this;
           outputBuf->writecallback = bufferWrite;
  @@ -170,7 +164,7 @@
           KHTMLView *view = m_sourceDocument->view();
           const xmlChar *method;
           XSLT_GET_IMPORT_PTR(method, sheet, method);
  -        if (method == NULL && resultDoc->type == XML_HTML_DOCUMENT_NODE)
  +        if (method == 0 && resultDoc->type == XML_HTML_DOCUMENT_NODE)
               method = (const xmlChar *)"html";
           if (xmlStrEqual(method, (const xmlChar *)"html"))
               result = m_sourceDocument->impl()->createHTMLDocument(view);
  @@ -178,7 +172,7 @@
               result = m_sourceDocument->impl()->createDocument(view);
           result->attach();
           result->docLoader()->setShowAnimations(m_sourceDocument->docLoader()->showAnimations());
  -        result->setTransformSourceDocument(m_sourceDocument);
  +        result->setTransformSourceDocument(m_sourceDocument.get());
   
           if (xmlStrEqual(method, (const xmlChar *)"text")) {
               // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing the text.
  @@ -198,7 +192,7 @@
           // in place. We have to do this only if we're rendering the result document.
           if (view) {
               view->clear();
  -            view->part()->replaceDocImpl(result);
  +            view->part()->replaceDocImpl(result.get());
           }
           
           result->open();
  
  
  
  1.4       +9 -7      WebCore/khtml/xsl/xslt_processorimpl.h
  
  Index: xslt_processorimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- xslt_processorimpl.h	30 Jun 2005 05:57:17 -0000	1.3
  +++ xslt_processorimpl.h	10 Oct 2005 23:48:55 -0000	1.4
  @@ -30,6 +30,7 @@
   
   #include <libxslt/transform.h>
   
  +#include <misc/shared.h>
   #include <qstring.h>
   
   namespace DOM {
  @@ -45,23 +46,24 @@
       ~XSLTProcessorImpl();
       
       // Method for transforming a source document into a result document.
  -    DocumentImpl* transformDocument(DocumentImpl* sourceDoc);
  +    SharedPtr<DocumentImpl> transformDocument(DocumentImpl* sourceDoc);
   
       // Convert a libxml doc ptr to a KHTML DOM Document
  -    DocumentImpl* documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet);
  +    SharedPtr<DocumentImpl> documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet);
       
       // Helpers
       void addToResult(const char* buffer, int len);
       
  -    XSLStyleSheetImpl *stylesheet() { return m_stylesheet; }
  -    DocumentImpl *sourceDocument() { return m_sourceDocument; }
  +    XSLStyleSheetImpl *stylesheet() { return m_stylesheet.get(); }
  +    DocumentImpl *sourceDocument() { return m_sourceDocument.get(); }
       
  -protected:
  -    XSLStyleSheetImpl* m_stylesheet;
  +private:
  +    SharedPtr<XSLStyleSheetImpl> m_stylesheet;
       QString m_resultOutput;
  -    DocumentImpl* m_sourceDocument;
  +    SharedPtr<DocumentImpl> m_sourceDocument;
   };
   
   }
  +
   #endif
   #endif
  
  
  



More information about the webkit-changes mailing list