texinfo/MiscXS-avoid-memory-leak.patch
2019-09-30 11:18:22 -04:00

98 lines
2.8 KiB
Diff

From 690b130f6ef5e5b1112087a0378669b6d01ea3c5 Mon Sep 17 00:00:00 2001
From: Gavin Smith <gavinsmith0123@gmail.com>
Date: Thu, 16 Aug 2018 15:56:11 +0000
Subject: [PATCH 143/759] MiscXS avoid memory leak
git-svn-id: svn://127.0.0.1/svn_repo/texinfo/trunk@8095 39fee189-59d7-47db-b5d4-205258b72aed
---
ChangeLog | 8 ++++++++
tp/Texinfo/XS/misc.c | 39 ++++++++++++++++++++++-----------------
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/tp/Texinfo/MiscXS/misc.c b/tp/Texinfo/MiscXS/misc.c
index 40c8992e7..e013b1928 100644
--- a/tp/Texinfo/MiscXS/misc.c
+++ b/tp/Texinfo/MiscXS/misc.c
@@ -612,21 +612,24 @@ void xs_parse_texi_regex (SV *text_in,
if (*text == '@' && isalnum(text[1]))
{
char *p, *q;
+ static char *s;
p = text + 1;
q = text + 2;
while (isalnum (*q) || *q == '-' || *q == '_')
q++;
- *at_command = malloc (q - p + 1);
- memcpy (*at_command, p, q - p);
- (*at_command)[q - p] = '\0';
+
+ s = realloc (s, q - p + 1);
+ memcpy (s, p, q - p);
+ s[q - p] = '\0';
+ *at_command = s;
}
else
{
if (*text == '{')
{
- *open_brace = strdup ("{");
- *separator_match = strdup ("{");
+ *open_brace = "{";
+ *separator_match = "{";
}
else if (*text == '@'
@@ -635,16 +638,18 @@ void xs_parse_texi_regex (SV *text_in,
"*-^`=:|/\\",
text[1]))
{
- *single_letter_command = malloc (2);
- (*single_letter_command)[0] = text[1];
- (*single_letter_command)[1] = '\0';
+ static char a[2];
+ *single_letter_command = a;
+ a[0] = text[1];
+ a[1] = '\0';
}
else if (strchr ("{}@,:\t.\f", *text))
{
- *separator_match = malloc (2);
- (*separator_match)[0] = *text;
- (*separator_match)[1] = '\0';
+ static char a[2];
+ *separator_match = a;
+ a[0] = *text;
+ a[1] = '\0';
}
else
@@ -652,17 +657,17 @@ void xs_parse_texi_regex (SV *text_in,
char *p;
if (*text == '*')
- {
- *asterisk = strdup ("*");
- }
+ *asterisk = "*";
p = text;
p += strcspn (p, "{}@,:\t.\n\f");
if (p > text)
{
- *new_text = malloc (p - text + 1);
- memcpy (*new_text, text, p - text);
- (*new_text)[p - text] = '\0';
+ static char *s;
+ s = realloc (s, p - text + 1);
+ memcpy (s, text, p - text);
+ s[p - text] = '\0';
+ *new_text = s;
}
}
}
--
2.19.1