@@ -1474,15 +1474,15 @@ xmlOutputBufferPtr
14741474__xmlOutputBufferCreateFilename (const char * URI ,
14751475 xmlCharEncodingHandlerPtr encoder ,
14761476 int compression ) {
1477- xmlOutputBufferPtr ret ;
1477+ xmlOutputBufferPtr ret = NULL ;
14781478 xmlURIPtr puri ;
14791479 int i = 0 ;
14801480 char * unescaped = NULL ;
14811481
14821482 xmlInitParser ();
14831483
14841484 if (URI == NULL )
1485- return ( NULL ) ;
1485+ goto error ;
14861486
14871487 puri = xmlParseURI (URI );
14881488 if (puri != NULL ) {
@@ -1493,8 +1493,7 @@ __xmlOutputBufferCreateFilename(const char *URI,
14931493 unescaped = xmlURIUnescapeString (URI , 0 , NULL );
14941494 if (unescaped == NULL ) {
14951495 xmlFreeURI (puri );
1496- xmlCharEncCloseFunc (encoder );
1497- return (NULL );
1496+ goto error ;
14981497 }
14991498 URI = unescaped ;
15001499 }
@@ -1505,10 +1504,9 @@ __xmlOutputBufferCreateFilename(const char *URI,
15051504 * Allocate the Output buffer front-end.
15061505 */
15071506 ret = xmlAllocOutputBuffer (encoder );
1508- if (ret == NULL ) {
1509- xmlFree (unescaped );
1510- return (NULL );
1511- }
1507+ encoder = NULL ;
1508+ if (ret == NULL )
1509+ goto error ;
15121510
15131511 /*
15141512 * Try to find one of the output accept method accepting that scheme
@@ -1539,7 +1537,10 @@ __xmlOutputBufferCreateFilename(const char *URI,
15391537 ret = NULL ;
15401538 }
15411539
1540+ error :
15421541 xmlFree (unescaped );
1542+ if (encoder != NULL )
1543+ xmlCharEncCloseFunc (encoder );
15431544 return (ret );
15441545}
15451546
@@ -1620,7 +1621,10 @@ xmlOutputBufferPtr
16201621xmlOutputBufferCreateFile (FILE * file , xmlCharEncodingHandlerPtr encoder ) {
16211622 xmlOutputBufferPtr ret ;
16221623
1623- if (file == NULL ) return (NULL );
1624+ if (file == NULL ) {
1625+ xmlCharEncCloseFunc (encoder );
1626+ return (NULL );
1627+ }
16241628
16251629 ret = xmlAllocOutputBuffer (encoder );
16261630 if (ret != NULL ) {
@@ -1648,7 +1652,10 @@ xmlOutputBufferCreateBuffer(xmlBufferPtr buffer,
16481652 xmlCharEncodingHandlerPtr encoder ) {
16491653 xmlOutputBufferPtr ret ;
16501654
1651- if (buffer == NULL ) return (NULL );
1655+ if (buffer == NULL ) {
1656+ xmlCharEncCloseFunc (encoder );
1657+ return (NULL );
1658+ }
16521659
16531660 ret = xmlOutputBufferCreateIO (xmlBufferWrite , NULL , (void * ) buffer ,
16541661 encoder );
@@ -1913,7 +1920,10 @@ xmlOutputBufferPtr
19131920xmlOutputBufferCreateFd (int fd , xmlCharEncodingHandlerPtr encoder ) {
19141921 xmlOutputBufferPtr ret ;
19151922
1916- if (fd < 0 ) return (NULL );
1923+ if (fd < 0 ) {
1924+ xmlCharEncCloseFunc (encoder );
1925+ return (NULL );
1926+ }
19171927
19181928 ret = xmlAllocOutputBuffer (encoder );
19191929 if (ret != NULL ) {
0 commit comments