From d916a50c77f41655b4af6bab994a771a161ea532 Mon Sep 17 00:00:00 2001 From: Gavin Smith Date: Thu, 16 Aug 2018 16:24:40 +0000 Subject: [PATCH 145/759] XS avoid memory leaks git-svn-id: svn://127.0.0.1/svn_repo/texinfo/trunk@8097 39fee189-59d7-47db-b5d4-205258b72aed --- ChangeLog | 5 +++++ tp/Texinfo/XS/misc.c | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tp/Texinfo/MiscXS/misc.c b/tp/Texinfo/MiscXS/misc.c index e013b1928..6962f1b08 100644 --- a/tp/Texinfo/MiscXS/misc.c +++ b/tp/Texinfo/MiscXS/misc.c @@ -437,9 +437,11 @@ NEW_TEXT: char * xs_process_text (char *text) { - char *new, *p, *q; + static char *new; + char *p, *q; - new = strdup (text); + new = realloc (new, strlen (text) + 1); + strcpy (new, text); p = q = new; while (*p) @@ -489,7 +491,7 @@ char * xs_unicode_text (char *text, int in_code) { char *p, *q; - char *new; + static char *new; int new_space, new_len; dTHX; /* Perl boilerplate. */ @@ -499,7 +501,7 @@ xs_unicode_text (char *text, int in_code) p = text; new_space = strlen (text); - new = malloc (new_space + 1); + new = realloc (new, new_space + 1); new_len = 0; #define ADD3(s) \ if (new_len + 2 >= new_space - 1) \ -- 2.19.1