Fix mem leak in sfntly

This commit is contained in:
Kovid Goyal 2012-10-30 16:09:45 +05:30
parent d4854e20ec
commit f8d9dead20
2 changed files with 16 additions and 1 deletions

View File

@ -497,7 +497,7 @@ do_subset(const char *data, Py_ssize_t sz, Ptr<CharacterPredicate> &predicate) {
return NULL;
}
font = fonts[0].Detach();
font = fonts[0];
if (font->num_tables() == 0) {
PyErr_SetString(Error, "Loaded font has 0 tables.");
return NULL;

View File

@ -76,6 +76,21 @@ def print_stats(old_stats, new_stats):
'%10s'%nsz, ' ', '%5.1f %%'%np, suffix)
prints('='*80)
def test_mem():
load_sfntly()
from calibre.utils.mem import memory
import gc
gc.collect()
start_mem = memory()
raw = P('fonts/liberation/LiberationSerif-Regular.ttf', data=True)
calls = 1000
for i in xrange(calls):
subset(raw, (), (('a', 'z'),))
del raw
for i in xrange(3): gc.collect()
print ('Leaked memory per call:', (memory() - start_mem)/calls*1024, 'KB')
def main(args):
import sys, time
from calibre import prints