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

Eric eseidel at opensource.apple.com
Thu Dec 29 21:33:17 PST 2005


eseidel     05/12/29 21:33:17

  Modified:    .        ChangeLog
               khtml/xsl xslt_processorimpl.cpp
  Log:
  Bug #: 6101
  Submitted by: eseidel
  Reviewed by: mjs
          Leaks in XSLTProcessorImpl due to early exit in failure case
          http://bugzilla.opendarwin.org/show_bug.cgi?id=6101
  
          * khtml/xsl/xslt_processorimpl.cpp:
          (DOM::xmlDocPtrFromNode): add "shouldDelete" argument
          (DOM::XSLTProcessorImpl::transformToString): delete new'd xmlDoc
  
  Revision  Changes    Path
  1.61      +11 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- ChangeLog	30 Dec 2005 05:11:36 -0000	1.60
  +++ ChangeLog	30 Dec 2005 05:33:16 -0000	1.61
  @@ -10,6 +10,17 @@
   
   2005-12-29  Eric Seidel  <eseidel at apple.com>
   
  +        Reviewed by mjs.
  +
  +        Leaks in XSLTProcessorImpl due to early exit in failure case
  +        http://bugzilla.opendarwin.org/show_bug.cgi?id=6101
  +
  +        * khtml/xsl/xslt_processorimpl.cpp:
  +        (DOM::xmlDocPtrFromNode): add "shouldDelete" argument
  +        (DOM::XSLTProcessorImpl::transformToString): delete new'd xmlDoc
  +
  +2005-12-29  Eric Seidel  <eseidel at apple.com>
  +
           File accidentally omitted from previous commit.
   
           Remove QDict from khtml/html
  
  
  
  1.21      +21 -16    WebCore/khtml/xsl/xslt_processorimpl.cpp
  
  Index: xslt_processorimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.cpp,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- xslt_processorimpl.cpp	23 Dec 2005 03:57:25 -0000	1.20
  +++ xslt_processorimpl.cpp	30 Dec 2005 05:33:17 -0000	1.21
  @@ -257,7 +257,7 @@
       return cachedStylesheet->compileStyleSheet();
   }
   
  -static inline xmlDocPtr xmlDocPtrFromNode(NodeImpl *sourceNode)
  +static inline xmlDocPtr xmlDocPtrFromNode(NodeImpl *sourceNode, bool &shouldDelete)
   {
       RefPtr<DocumentImpl> ownerDocument = sourceNode->getDocument();
       bool sourceIsDocument = (sourceNode == ownerDocument.get());
  @@ -265,8 +265,10 @@
       xmlDocPtr sourceDoc = 0;
       if (sourceIsDocument)
           sourceDoc = (xmlDocPtr)ownerDocument->transformSource();
  -    if (!sourceDoc)
  +    if (!sourceDoc) {
           sourceDoc = (xmlDocPtr)xmlDocPtrForString(createMarkup(sourceNode), sourceIsDocument ? ownerDocument->URL() : QString());
  +        shouldDelete = (sourceDoc != 0);
  +    }
       return sourceDoc;
   }
   
  @@ -302,23 +304,26 @@
       }
       cachedStylesheet->clearDocuments();
       
  -    xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode);
  -    const char **params = xsltParamArrayFromParameterMap(m_parameters);
  -    xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, params);
  -    freeXsltParamArray(params);
  +    bool success = false;
  +    bool shouldFreeSourceDoc = false;
  +    if (xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode, shouldFreeSourceDoc)) {
  +        const char **params = xsltParamArrayFromParameterMap(m_parameters);
  +        xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, params);
  +        freeXsltParamArray(params);
  +        if (shouldFreeSourceDoc)
  +            xmlFreeDoc(sourceDoc);
  +        
  +        if (success = saveResultToString(resultDoc, sheet, resultString)) {
  +            mimeType = resultMIMEType(resultDoc, sheet);
  +            resultEncoding = (char *)resultDoc->encoding;
  +        }
  +        xmlFreeDoc(resultDoc);
  +    }
       
       setXSLTLoadCallBack(0, 0, 0);
  -    
  -    if (!saveResultToString(resultDoc, sheet, resultString))
  -        return false;
  -    
  -    mimeType = resultMIMEType(resultDoc, sheet);
  -    resultEncoding = (char *)resultDoc->encoding;
  -    
       xsltFreeStylesheet(sheet);
  -    xmlFreeDoc(resultDoc);
  -    
  -    return true;
  +
  +    return success;
   }
   
   RefPtr<DocumentImpl> XSLTProcessorImpl::transformToDocument(NodeImpl *sourceNode)
  
  
  



More information about the webkit-changes mailing list