Skip to content

Commit 577f9c7

Browse files
authored
Backport 37ed86f (ruby#10248)
merge revision(s) 37ed86f: [Backport #--ticket=20161] Fix memory leak in regexp grapheme clusters [Bug #20161] The cc->mbuf gets overwritten, so we need to free it to not leak memory. For example: str = "hello world".encode(Encoding::UTF_32LE) 10.times do 1_000.times do str.grapheme_clusters end puts `ps -o rss= -p #{$$}` end Before: 15536 15760 15920 16144 16304 16480 16640 16784 17008 17280 After: 15584 15584 15760 15824 15888 15888 15888 15888 16048 16112 --- regparse.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
1 parent ade02f3 commit 577f9c7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

regparse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6105,7 +6105,8 @@ node_extended_grapheme_cluster(Node** np, ScanEnv* env)
61056105
R_ERR(add_code_range(&(cc->mbuf), env, 0x000A, 0x000A)); /* CR */
61066106
R_ERR(add_code_range(&(cc->mbuf), env, 0x000D, 0x000D)); /* LF */
61076107
R_ERR(not_code_range_buf(env->enc, cc->mbuf, &inverted_buf, env));
6108-
cc->mbuf = inverted_buf; /* TODO: check what to do with buffer before inversion */
6108+
bbuf_free(cc->mbuf);
6109+
cc->mbuf = inverted_buf;
61096110

61106111
env->warnings_flag &= dup_not_warned; /* TODO: fix false warning */
61116112
}

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 0
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 12
14+
#define RUBY_PATCHLEVEL 13
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy