Skip to content

Commit 8a7369f

Browse files
authored
Merge pull request #93 from jameswyper/issue-91-fix-memory-leak-flac-picture
Fix for issue #91
2 parents 86567b7 + 6d28d7b commit 8a7369f

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ if you don't have it):
7373

7474
bundle install
7575

76-
Regenerate SWIG wrappers if you made changes in `.i` files (use version 3.0.7 of SWIG):
76+
Regenerate SWIG wrappers if you made changes in `.i` files (use version 3.0.7 of SWIG - 3.0.8 through 3.0.12 will not work):
7777

7878
rake swig
7979

ext/taglib_flac/taglib_flac.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@
8686
SWIG_RubyRemoveTracking(properties);
8787
}
8888

89+
TagLib::List<TagLib::FLAC::Picture *> list = file->pictureList();
90+
for (TagLib::List<TagLib::FLAC::Picture *>::ConstIterator it = list.begin(); it != list.end(); it++) {
91+
TagLib::FLAC::Picture *picture = (*it);
92+
SWIG_RubyUnlinkObjects(picture);
93+
SWIG_RubyRemoveTracking(picture);
94+
}
95+
8996
SWIG_RubyUnlinkObjects(ptr);
9097
SWIG_RubyRemoveTracking(ptr);
9198

ext/taglib_flac/taglib_flac_wrap.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,13 @@ SWIGINTERN void TagLib_FLAC_File_close(TagLib::FLAC::File *self){
22102210
SWIG_RubyRemoveTracking(properties);
22112211
}
22122212

2213+
TagLib::List<TagLib::FLAC::Picture *> list = file->pictureList();
2214+
for (TagLib::List<TagLib::FLAC::Picture *>::ConstIterator it = list.begin(); it != list.end(); it++) {
2215+
TagLib::FLAC::Picture *picture = (*it);
2216+
SWIG_RubyUnlinkObjects(picture);
2217+
SWIG_RubyRemoveTracking(picture);
2218+
}
2219+
22132220
SWIG_RubyUnlinkObjects(ptr);
22142221
SWIG_RubyRemoveTracking(ptr);
22152222

test/data/flac_nopic.flac

34.1 KB
Binary file not shown.

test/flac_picture_memory_test.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require File.join(File.dirname(__FILE__), 'helper')
2+
3+
class TestFlacPictureMemory < Test::Unit::TestCase
4+
5+
N = 10000
6+
7+
context "TagLib::FLAC::Picture" do
8+
9+
setup do
10+
11+
end
12+
13+
should "release memory when closing flac file with picture data" do
14+
c = 0
15+
N.times do
16+
TagLib::FLAC::File.open("test/data/flac.flac", false) do |f|
17+
f.picture_list.each do |p|
18+
x = p.data
19+
c = c + 1
20+
end
21+
end
22+
end
23+
assert_equal N,c
24+
end
25+
26+
should "process a flac file without picture data" do
27+
c = 0
28+
N.times do
29+
TagLib::FLAC::File.open("test/data/flac_nopic.flac", false) do |f|
30+
f.picture_list.each do |p|
31+
x = p.data
32+
c = c + 1
33+
end
34+
end
35+
end
36+
assert_equal 0,c
37+
end
38+
39+
teardown do
40+
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)