aboutsummaryrefslogtreecommitdiffstats
path: root/node.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-09-29 13:45:25 -0400
committerPeter Zhu <peter@peterzhu.ca>2023-09-29 16:51:17 -0400
commit97564ddf2baa518e4bda5b7a59111943dc13f210 (patch)
tree4fa31bdcfc90da6b535503e297ebed6ea4ec0ddc /node.c
parentf88f5b59e8cd58f5a88013d192c8141ea0bb8499 (diff)
downloadruby-97564ddf2baa518e4bda5b7a59111943dc13f210.tar.gz
Fix memory leak in the parser
Reproduction script: ``` require "ripper" 10.times do 20_000.times do Ripper.parse("") end puts `ps -o rss= -p #{$$}` end ``` Before: ``` 28032 34432 40704 47232 53632 60032 66432 72832 79232 85632 ``` After: ``` 21760 21760 21760 21760 21760 21760 21760 21760 21760 21760 ```
Diffstat (limited to 'node.c')
-rw-r--r--node.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/node.c b/node.c
index 1f0e457f52..19fe84c672 100644
--- a/node.c
+++ b/node.c
@@ -154,6 +154,10 @@ node_buffer_list_free(rb_ast_t *ast, node_buffer_list_t * nb)
nbe = nbe->next;
xfree(buf);
}
+
+ /* The last node_buffer_elem_t is allocated in the node_buffer_t, so we
+ * only need to free the nodes. */
+ xfree(nbe->nodes);
}
struct rb_ast_local_table_link {