@matheusbsbs / matheus-bagliano / commits / 5d17d765ca
Fork 0

Fix pool handling in git-svnimport to avoid memory leaks.

- Create an explicit one-and-only root pool. - Closely follow examples in SVN::Core man page. Before calling a subversion function, create a subpool of our root pool and make it the new default pool. - Create a subpool for looping over svn revisions and clear this subpool (i.e. it mark for reuse, don't decallocate it) at the start of the loop instead of allocating new memory with each iteration. See http://marc.info/?l=git&m=118554191513822&w=2 for a detailed explanation of the issue. Signed-off-by: Stefan Sperling <stsp@elego.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Sperling committed Sep 24, 2007 at 12:57 UTC 5d17d765ca754f3e9d87110394a0a397ea7ac2cf
1 file changed +12 -11
git-svnimport.perl
+12 -11
@@ -54,6 +54,7 @@ my $branch_name = $opt_b || "branches";
54 my $project_name = $opt_P || "";
55 $project_name = "/" . $project_name if ($project_name);
56 my $repack_after = $opt_R || 1000;
57 +my $root_pool = SVN::Pool->new_default;
58
59 @ARGV == 1 or @ARGV == 2 or usage();
60
@@ -132,7 +133,7 @@ sub conn {
133 my $auth = SVN::Core::auth_open ([SVN::Client::get_simple_provider,
134 SVN::Client::get_ssl_server_trust_file_provider,
135 SVN::Client::get_username_provider]);
135 - my $s = SVN::Ra->new(url => $repo, auth => $auth);
136 + my $s = SVN::Ra->new(url => $repo, auth => $auth, pool => $root_pool);
137 die "SVN connection to $repo: $!\n" unless defined $s;
138 $self->{'svn'} = $s;
139 $self->{'repo'} = $repo;
@@ -147,11 +148,10 @@ sub file {
148
149 print "... $rev $path ...\n" if $opt_v;
150 my (undef, $properties);
150 - my $pool = SVN::Pool->new();
151 $path =~ s#^/*##;
152 + my $subpool = SVN::Pool::new_default_sub;
153 eval { (undef, $properties)
153 - = $self->{'svn'}->get_file($path,$rev,$fh,$pool); };
154 - $pool->clear;
154 + = $self->{'svn'}->get_file($path,$rev,$fh); };
155 if($@) {
156 return undef if $@ =~ /Attempted to get checksum/;
157 die $@;
@@ -185,6 +185,7 @@ sub ignore {
185
186 print "... $rev $path ...\n" if $opt_v;
187 $path =~ s#^/*##;
188 + my $subpool = SVN::Pool::new_default_sub;
189 my (undef,undef,$properties)
190 = $self->{'svn'}->get_dir($path,$rev,undef);
191 if (exists $properties->{'svn:ignore'}) {
@@ -202,6 +203,7 @@ sub ignore {
203 sub dir_list {
204 my($self,$path,$rev) = @_;
205 $path =~ s#^/*##;
206 + my $subpool = SVN::Pool::new_default_sub;
207 my ($dirents,undef,$properties)
208 = $self->{'svn'}->get_dir($path,$rev,undef);
209 return $dirents;
@@ -358,10 +360,9 @@ open BRANCHES,">>", "$git_dir/svn2git";
360
361 sub node_kind($$) {
362 my ($svnpath, $revision) = @_;
361 - my $pool=SVN::Pool->new;
363 $svnpath =~ s#^/*##;
363 - my $kind = $svn->{'svn'}->check_path($svnpath,$revision,$pool);
364 - $pool->clear;
364 + my $subpool = SVN::Pool::new_default_sub;
365 + my $kind = $svn->{'svn'}->check_path($svnpath,$revision);
366 return $kind;
367 }
368
@@ -889,7 +890,7 @@ sub commit_all {
890 # Recursive use of the SVN connection does not work
891 local $svn = $svn2;
892
892 - my ($changed_paths, $revision, $author, $date, $message, $pool) = @_;
893 + my ($changed_paths, $revision, $author, $date, $message) = @_;
894 my %p;
895 while(my($path,$action) = each %$changed_paths) {
896 $p{$path} = [ $action->action,$action->copyfrom_path, $action->copyfrom_rev, $path ];
@@ -925,14 +926,14 @@ print "Processing from $current_rev to $opt_l ...\n" if $opt_v;
926 my $from_rev;
927 my $to_rev = $current_rev - 1;
928
929 +my $subpool = SVN::Pool::new_default_sub;
930 while ($to_rev < $opt_l) {
931 + $subpool->clear;
932 $from_rev = $to_rev + 1;
933 $to_rev = $from_rev + $repack_after;
934 $to_rev = $opt_l if $opt_l < $to_rev;
935 print "Fetching from $from_rev to $to_rev ...\n" if $opt_v;
933 - my $pool=SVN::Pool->new;
934 - $svn->{'svn'}->get_log("/",$from_rev,$to_rev,0,1,1,\&commit_all,$pool);
935 - $pool->clear;
936 + $svn->{'svn'}->get_log("/",$from_rev,$to_rev,0,1,1,\&commit_all);
937 my $pid = fork();
938 die "Fork: $!\n" unless defined $pid;
939 unless($pid) {