mirror of
				https://gitlab.gnome.org/GNOME/libxml2.git
				synced 2025-10-24 13:33:01 +03:00 
			
		
		
		
	io: Make xmlOutputBufferCreate* not free encoder on error
Revert a530ff12 which was an inadvertent API change.
			
			
This commit is contained in:
		
							
								
								
									
										16
									
								
								HTMLtree.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								HTMLtree.c
									
									
									
									
									
								
							| @@ -559,8 +559,10 @@ htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc ATTRIBUTE_UNUSED, | ||||
|     if (htmlFindOutputEncoder(encoding, &handler) != XML_ERR_OK) | ||||
|         return(-1); | ||||
|     buf = xmlOutputBufferCreateFile(out, handler); | ||||
|     if (buf == NULL) | ||||
|     if (buf == NULL) { | ||||
|         xmlCharEncCloseFunc(handler); | ||||
|         return(-1); | ||||
|     } | ||||
|  | ||||
|     htmlNodeDumpInternal(buf, cur, NULL, format); | ||||
|  | ||||
| @@ -613,8 +615,10 @@ htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) { | ||||
|     if (htmlFindOutputEncoder((char *) cur->encoding, &handler) != XML_ERR_OK) | ||||
|         return; | ||||
|     buf = xmlAllocOutputBuffer(handler); | ||||
|     if (buf == NULL) | ||||
|     if (buf == NULL) { | ||||
|         xmlCharEncCloseFunc(handler); | ||||
| 	return; | ||||
|     } | ||||
|  | ||||
|     htmlDocContentDumpFormatOutput(buf, cur, NULL, format); | ||||
|  | ||||
| @@ -1202,8 +1206,10 @@ htmlDocDump(FILE *f, xmlDocPtr cur) { | ||||
|     if (htmlFindOutputEncoder((char *) cur->encoding, &handler) != XML_ERR_OK) | ||||
|         return(-1); | ||||
|     buf = xmlOutputBufferCreateFile(f, handler); | ||||
|     if (buf == NULL) | ||||
|     if (buf == NULL) { | ||||
|         xmlCharEncCloseFunc(handler); | ||||
|         return(-1); | ||||
|     } | ||||
|     htmlDocContentDumpOutput(buf, cur, NULL); | ||||
|  | ||||
|     ret = xmlOutputBufferClose(buf); | ||||
| @@ -1265,8 +1271,10 @@ htmlSaveFileFormat(const char *filename, xmlDocPtr cur, | ||||
|      * save the content to a temp buffer. | ||||
|      */ | ||||
|     buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); | ||||
|     if (buf == NULL) | ||||
|     if (buf == NULL) { | ||||
|         xmlCharEncCloseFunc(handler); | ||||
|         return(0); | ||||
|     } | ||||
|  | ||||
|     htmlDocContentDumpFormatOutput(buf, cur, encoding, format); | ||||
|  | ||||
|   | ||||
							
								
								
									
										26
									
								
								xmlIO.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								xmlIO.c
									
									
									
									
									
								
							| @@ -1509,7 +1509,7 @@ xmlAllocParserInputBuffer(xmlCharEncoding enc) { | ||||
| /** | ||||
|  * Create a buffered parser output | ||||
|  * | ||||
|  * Consumes `encoder` even in error case. | ||||
|  * Consumes `encoder` but not in error case. | ||||
|  * | ||||
|  * @param encoder  the encoding converter or NULL | ||||
|  * @returns the new parser output or NULL | ||||
| @@ -1520,13 +1520,11 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) { | ||||
|  | ||||
|     ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); | ||||
|     if (ret == NULL) { | ||||
|         xmlCharEncCloseFunc(encoder); | ||||
| 	return(NULL); | ||||
|     } | ||||
|     memset(ret, 0, sizeof(xmlOutputBuffer)); | ||||
|     ret->buffer = xmlBufCreate(MINLEN); | ||||
|     if (ret->buffer == NULL) { | ||||
|         xmlCharEncCloseFunc(encoder); | ||||
|         xmlFree(ret); | ||||
| 	return(NULL); | ||||
|     } | ||||
| @@ -1535,7 +1533,8 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) { | ||||
|     if (encoder != NULL) { | ||||
|         ret->conv = xmlBufCreate(MINLEN); | ||||
| 	if (ret->conv == NULL) { | ||||
|             xmlOutputBufferClose(ret); | ||||
|             xmlBufFree(ret->buffer); | ||||
|             xmlFree(ret); | ||||
| 	    return(NULL); | ||||
| 	} | ||||
|  | ||||
| @@ -1778,7 +1777,6 @@ __xmlOutputBufferCreateFilename(const char *URI, | ||||
|      * Allocate the Output buffer front-end. | ||||
|      */ | ||||
|     ret = xmlAllocOutputBuffer(encoder); | ||||
|     encoder = NULL; | ||||
|     if (ret == NULL) | ||||
|         goto error; | ||||
|  | ||||
| @@ -1807,14 +1805,14 @@ __xmlOutputBufferCreateFilename(const char *URI, | ||||
|     } | ||||
|  | ||||
|     if (ret->context == NULL) { | ||||
|         /* Don't free encoder */ | ||||
|         ret->encoder = NULL; | ||||
|         xmlOutputBufferClose(ret); | ||||
| 	ret = NULL; | ||||
|     } | ||||
|  | ||||
| error: | ||||
|     xmlFree(unescaped); | ||||
|     if (encoder != NULL) | ||||
|         xmlCharEncCloseFunc(encoder); | ||||
|     return(ret); | ||||
| } | ||||
|  | ||||
| @@ -1824,7 +1822,7 @@ error: | ||||
|  * Automatic support for ZLIB/Compress compressed document is provided | ||||
|  * by default if found at compile-time. | ||||
|  * | ||||
|  * Consumes `encoder` even in error case. | ||||
|  * Consumes `encoder` but not in error case. | ||||
|  * | ||||
|  * @param URI  a C string containing the URI or filename | ||||
|  * @param encoder  the encoding converter or NULL | ||||
| @@ -1877,7 +1875,7 @@ xmlParserInputBufferCreateFile(FILE *file, xmlCharEncoding enc) { | ||||
|  * Create a buffered output for the progressive saving to a `FILE *` | ||||
|  * buffered C I/O. | ||||
|  * | ||||
|  * Consumes `encoder` even in error case. | ||||
|  * Consumes `encoder` but not in error case. | ||||
|  * | ||||
|  * @param file  a `FILE *` | ||||
|  * @param encoder  the encoding converter or NULL | ||||
| @@ -1888,7 +1886,6 @@ xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) { | ||||
|     xmlOutputBufferPtr ret; | ||||
|  | ||||
|     if (file == NULL) { | ||||
|         xmlCharEncCloseFunc(encoder); | ||||
|         return(NULL); | ||||
|     } | ||||
|  | ||||
| @@ -1905,7 +1902,7 @@ xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) { | ||||
| /** | ||||
|  * Create a buffered output for the progressive saving to a xmlBuffer | ||||
|  * | ||||
|  * Consumes `encoder` even in error case. | ||||
|  * Consumes `encoder` but not in error case. | ||||
|  * | ||||
|  * @param buffer  a xmlBufferPtr | ||||
|  * @param encoder  the encoding converter or NULL | ||||
| @@ -1917,7 +1914,6 @@ xmlOutputBufferCreateBuffer(xmlBufferPtr buffer, | ||||
|     xmlOutputBufferPtr ret; | ||||
|  | ||||
|     if (buffer == NULL) { | ||||
|         xmlCharEncCloseFunc(encoder); | ||||
|         return(NULL); | ||||
|     } | ||||
|  | ||||
| @@ -2167,7 +2163,7 @@ xmlNewInputBufferString(const char *str, xmlParserInputFlags flags) { | ||||
|  * Create a buffered output for the progressive saving | ||||
|  * to a file descriptor | ||||
|  * | ||||
|  * Consumes `encoder` even in error case. | ||||
|  * Consumes `encoder` but not in error case. | ||||
|  * | ||||
|  * @param fd  a file descriptor number | ||||
|  * @param encoder  the encoding converter or NULL | ||||
| @@ -2178,7 +2174,6 @@ xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) { | ||||
|     xmlOutputBufferPtr ret; | ||||
|  | ||||
|     if (fd < 0) { | ||||
|         xmlCharEncCloseFunc(encoder); | ||||
|         return(NULL); | ||||
|     } | ||||
|  | ||||
| @@ -2239,7 +2234,7 @@ xmlParserInputBufferCreateIO(xmlInputReadCallback   ioread, | ||||
|  * Create a buffered output for the progressive saving | ||||
|  * to an I/O handler | ||||
|  * | ||||
|  * Consumes `encoder` even in error case. | ||||
|  * Consumes `encoder` but not in error case. | ||||
|  * | ||||
|  * @param iowrite  an I/O write function | ||||
|  * @param ioclose  an I/O close function | ||||
| @@ -2254,7 +2249,6 @@ xmlOutputBufferCreateIO(xmlOutputWriteCallback   iowrite, | ||||
|     xmlOutputBufferPtr ret; | ||||
|  | ||||
|     if (iowrite == NULL) { | ||||
|         xmlCharEncCloseFunc(encoder); | ||||
|         return(NULL); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1836,6 +1836,7 @@ xmlSaveToFd(int fd, const char *encoding, int options) | ||||
|     if (ret == NULL) return(NULL); | ||||
|     ret->buf = xmlOutputBufferCreateFd(fd, ret->handler); | ||||
|     if (ret->buf == NULL) { | ||||
|         xmlCharEncCloseFunc(ret->handler); | ||||
| 	xmlFreeSaveCtxt(ret); | ||||
| 	return(NULL); | ||||
|     } | ||||
| @@ -1868,6 +1869,7 @@ xmlSaveToFilename(const char *filename, const char *encoding, int options) | ||||
|     ret->buf = xmlOutputBufferCreateFilename(filename, ret->handler, | ||||
|                                              compression); | ||||
|     if (ret->buf == NULL) { | ||||
|         xmlCharEncCloseFunc(ret->handler); | ||||
| 	xmlFreeSaveCtxt(ret); | ||||
| 	return(NULL); | ||||
|     } | ||||
| @@ -1899,6 +1901,7 @@ xmlSaveToBuffer(xmlBufferPtr buffer, const char *encoding, int options) | ||||
|     if (ret == NULL) return(NULL); | ||||
|     ret->buf = xmlOutputBufferCreateBuffer(buffer, ret->handler); | ||||
|     if (ret->buf == NULL) { | ||||
|         xmlCharEncCloseFunc(ret->handler); | ||||
| 	xmlFreeSaveCtxt(ret); | ||||
| 	return(NULL); | ||||
|     } | ||||
| @@ -1933,6 +1936,7 @@ xmlSaveToIO(xmlOutputWriteCallback iowrite, | ||||
|     if (ret == NULL) return(NULL); | ||||
|     ret->buf = xmlOutputBufferCreateIO(iowrite, ioclose, ioctx, ret->handler); | ||||
|     if (ret->buf == NULL) { | ||||
|         xmlCharEncCloseFunc(ret->handler); | ||||
| 	xmlFreeSaveCtxt(ret); | ||||
| 	return(NULL); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user