Skip to content

Commit 020e24b

Browse files
committed
Fix memory leak in Rugged::Tree.diff
If `Rugged::Tree.diff` can't unwrap the repository object passed in, it can leak memory allocated in `rugged_parse_diff_options`. Before this commit, memory usage for this script will grow unbounded: ```ruby require 'rugged' loop do begin Rugged::Tree.diff nil, nil, nil, { paths: ['x' * 90] } rescue TypeError end end ``` To fix this, just try to unwrap the repository object before calling `rugged_parse_diff_options`.
1 parent e3f2d95 commit 020e24b

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

ext/rugged/rugged_tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,8 @@ static VALUE rb_git_tree_diff_(int argc, VALUE *argv, VALUE self)
484484
int error;
485485

486486
rb_scan_args(argc, argv, "22", &rb_repo, &rb_self, &rb_other, &rb_options);
487-
rugged_parse_diff_options(&opts, rb_options);
488-
489487
Data_Get_Struct(rb_repo, git_repository, repo);
488+
rugged_parse_diff_options(&opts, rb_options);
490489

491490
if (!NIL_P(rb_self)) {
492491
if (!rb_obj_is_kind_of(rb_self, rb_cRuggedTree))

0 commit comments

Comments
 (0)