[-] 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:
ejurgensen
2020-03-27 23:04:18 +01:00
parent 2d8521139c
commit dbc798da4f
6 changed files with 103 additions and 11 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -31,7 +31,6 @@
#include <stdbool.h>
#include <gcrypt.h>
#include <mxml.h>
#include <event2/buffer.h>
#include <event2/http.h>

View File

@@ -39,7 +39,7 @@
#include <time.h>
#include <event2/buffer.h>
#include <mxml.h>
#include "mxml-compat.h"
#include "conffile.h"

View File

@@ -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 */