mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 07:05:57 -05:00
[-] Workaround for mxml 2.10 memleak
2.10's mxmlDelete memleaks, and mxml is used in many parts of forked-daapd. So to avoid that we ship upstream's fixed version of mxmlDelete and use that.
This commit is contained in:
parent
2d8521139c
commit
dbc798da4f
15
configure.ac
15
configure.ac
@ -113,10 +113,16 @@ FORK_FUNC_REQUIRE([COMMON], [GNU libunistring], [LIBUNISTRING], [unistring],
|
||||
|
||||
FORK_MODULES_CHECK([FORKED], [ZLIB], [zlib], [deflate], [zlib.h])
|
||||
FORK_MODULES_CHECK([FORKED], [CONFUSE], [libconfuse >= 3.0], [cfg_init], [confuse.h])
|
||||
FORK_MODULES_CHECK([FORKED], [MINIXML], [mxml], [mxmlNewElement], [mxml.h],
|
||||
[AC_CHECK_FUNCS([mxmlGetOpaque] [mxmlGetText] [mxmlGetType] [mxmlGetFirstChild])])
|
||||
|
||||
dnl SQLite3 requires extra checks
|
||||
FORK_MODULES_CHECK([FORKED], [MINIXML], [mxml],
|
||||
[mxmlNewElement], [mxml.h],
|
||||
[dnl check for old versions which have a serious memleak
|
||||
AC_CHECK_FUNCS([mxmlGetOpaque] [mxmlGetText] [mxmlGetType] [mxmlGetFirstChild])
|
||||
PKG_CHECK_EXISTS([libevent >= 2.11], [],
|
||||
[AC_DEFINE([HAVE_MXML_OLD], 1,
|
||||
[Define to 1 if you have libmxml < 2.11)])])
|
||||
])
|
||||
|
||||
FORK_MODULES_CHECK([COMMON], [SQLITE3], [sqlite3 >= 3.5.0],
|
||||
[sqlite3_initialize], [sqlite3.h],
|
||||
[dnl Check that SQLite3 has the unlock notify API built-in
|
||||
@ -137,7 +143,6 @@ FORK_MODULES_CHECK([COMMON], [SQLITE3], [sqlite3 >= 3.5.0],
|
||||
[AC_MSG_RESULT([[runtime will tell]])])
|
||||
])
|
||||
|
||||
dnl libevent2 requires version checks
|
||||
FORK_MODULES_CHECK([FORKED], [LIBEVENT], [libevent >= 2],
|
||||
[event_base_new], [event2/event.h],
|
||||
[dnl check for old version
|
||||
@ -146,7 +151,6 @@ FORK_MODULES_CHECK([FORKED], [LIBEVENT], [libevent >= 2],
|
||||
[Define to 1 if you have libevent 2 (<2.1.4)])])
|
||||
])
|
||||
|
||||
dnl json-c version checks
|
||||
FORK_MODULES_CHECK([FORKED], [JSON_C], [json-c],
|
||||
[json_tokener_parse], [json.h],
|
||||
[dnl check for old version
|
||||
@ -155,7 +159,6 @@ FORK_MODULES_CHECK([FORKED], [JSON_C], [json-c],
|
||||
[Define to 1 if you have json-c < 0.11])])
|
||||
])
|
||||
|
||||
dnl antlr version checks
|
||||
FORK_FUNC_REQUIRE([FORKED], [ANTLR3 C runtime], [ANTLR3C], [antlr3c],
|
||||
[antlr3BaseRecognizerNew], [antlr3.h],
|
||||
[AC_CHECK_FUNC([[antlr3NewAsciiStringInPlaceStream]],
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <mxml.h>
|
||||
#include "mxml-compat.h"
|
||||
|
||||
#include "httpd_rsp.h"
|
||||
#include "logger.h"
|
||||
|
@ -53,7 +53,8 @@
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <mxml.h>
|
||||
|
||||
#include "mxml-compat.h"
|
||||
|
||||
#include "input.h"
|
||||
#include "misc.h"
|
||||
@ -64,7 +65,6 @@
|
||||
#include "player.h"
|
||||
#include "worker.h"
|
||||
#include "commands.h"
|
||||
#include "mxml-compat.h"
|
||||
|
||||
// Maximum number of pipes to watch for data
|
||||
#define PIPE_MAX_WATCH 4
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <gcrypt.h>
|
||||
#include <mxml.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/http.h>
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <event2/buffer.h>
|
||||
#include <mxml.h>
|
||||
|
||||
#include "mxml-compat.h"
|
||||
|
||||
#include "conffile.h"
|
||||
|
@ -1,6 +1,96 @@
|
||||
#ifndef __MXML_COMPAT_H__
|
||||
#define __MXML_COMPAT_H__
|
||||
|
||||
// mxml 2.10 has a memory leak in mxmlDelete, see https://github.com/michaelrsweet/mxml/issues/183
|
||||
// - and since this is the version in Ubuntu 18.04 LTS and Raspian Stretch, we
|
||||
// fix it by including a fixed mxmlDelete here. It should be removed once the
|
||||
// major distros no longer have 2.10. The below code is msweet's fixed mxml.
|
||||
#ifndef HAVE_MXML_OLD
|
||||
# include <mxml.h>
|
||||
#else
|
||||
// Trick to undefine mxml.h's mxmlDelete
|
||||
#define mxmlDelete mxmlDelete_memleak
|
||||
# include <mxml.h>
|
||||
#undef mxmlDelete
|
||||
|
||||
static void
|
||||
compat_mxml_free(mxml_node_t *node)
|
||||
{
|
||||
int i;
|
||||
|
||||
switch (node->type)
|
||||
{
|
||||
case MXML_ELEMENT :
|
||||
if (node->value.element.name)
|
||||
free(node->value.element.name);
|
||||
|
||||
if (node->value.element.num_attrs)
|
||||
{
|
||||
for (i = 0; i < node->value.element.num_attrs; i ++)
|
||||
{
|
||||
if (node->value.element.attrs[i].name)
|
||||
free(node->value.element.attrs[i].name);
|
||||
if (node->value.element.attrs[i].value)
|
||||
free(node->value.element.attrs[i].value);
|
||||
}
|
||||
|
||||
free(node->value.element.attrs);
|
||||
}
|
||||
break;
|
||||
case MXML_INTEGER :
|
||||
break;
|
||||
case MXML_OPAQUE :
|
||||
if (node->value.opaque)
|
||||
free(node->value.opaque);
|
||||
break;
|
||||
case MXML_REAL :
|
||||
break;
|
||||
case MXML_TEXT :
|
||||
if (node->value.text.string)
|
||||
free(node->value.text.string);
|
||||
break;
|
||||
case MXML_CUSTOM :
|
||||
if (node->value.custom.data &&
|
||||
node->value.custom.destroy)
|
||||
(*(node->value.custom.destroy))(node->value.custom.data);
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
static void
|
||||
mxmlDelete(mxml_node_t *node)
|
||||
{
|
||||
mxml_node_t *current,
|
||||
*next;
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
mxmlRemove(node);
|
||||
for (current = node->child; current; current = next)
|
||||
{
|
||||
if ((next = current->child) != NULL)
|
||||
{
|
||||
current->child = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((next = current->next) == NULL)
|
||||
{
|
||||
if ((next = current->parent) == node)
|
||||
next = NULL;
|
||||
}
|
||||
compat_mxml_free(current);
|
||||
}
|
||||
|
||||
compat_mxml_free(node);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* For compability with mxml 2.6 */
|
||||
#ifndef HAVE_MXMLGETTEXT
|
||||
__attribute__((unused)) static const char * /* O - Text string or NULL */
|
||||
|
Loading…
Reference in New Issue
Block a user