Skip to content

Commit b10a8a5

Browse files
committed
fix getMetadata memory leak
1 parent c207aaa commit b10a8a5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fitz/fitz.i

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,17 +1103,18 @@ struct Document
11031103
CLOSECHECK0(_getMetadata, """Get metadata.""")
11041104
char *_getMetadata(const char *key)
11051105
{
1106+
PyObject *res;
11061107
fz_document *doc = (fz_document *) $self;
11071108
int vsize;
11081109
char *value;
11091110
vsize = fz_lookup_metadata(gctx, doc, key, NULL, 0)+1;
11101111
if(vsize > 1) {
11111112
value = JM_Alloc(char, vsize);
11121113
fz_lookup_metadata(gctx, doc, key, value, vsize);
1113-
return value;
1114+
res = PyString_FromString(value);
1115+
PyMem_Del(value);
11141116
}
1115-
else
1116-
return NULL;
1117+
return res;
11171118
}
11181119
11191120
CLOSECHECK0(needsPass, """Indicate password required.""")

0 commit comments

Comments
 (0)