Skip to content

Commit

Permalink
Merge pull request #38 from rohanpm/header-resource-leaks
Browse files Browse the repository at this point in the history
Fix resource leaks when reading headers
  • Loading branch information
rohanpm authored Sep 24, 2024
2 parents 2c129e5 + cba07c7 commit c6a6b9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/rpmdyn/_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ffi.cdef(
"""
typedef void* Header;
typedef void* FD_t;
typedef void* rpm_data_t;
typedef void* rpmKeyring;
typedef uint32_t rpm_count_t;
Expand Down Expand Up @@ -43,7 +44,8 @@
rpmTagReturnType rpmTagGetReturnType(rpmTagVal);
void* fdDup(int);
FD_t fdDup(int);
int Fclose(FD_t);
rpmtd rpmtdNew();
rpmtd rpmtdFree(void*);
Expand Down Expand Up @@ -101,6 +103,7 @@ def cstr(value, nullable=False, error=None):

rpmTagGetReturnType = rpm.rpmTagGetReturnType
fdDup = rpmio.fdDup
Fclose = rpmio.Fclose

rpmtdNew = rpm.rpmtdNew
rpmtdFree = rpm.rpmtdFree
Expand Down
4 changes: 2 additions & 2 deletions src/rpmdyn/_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def hdrFromFdno(self, fd):

assert isinstance(fd, int)

rpmfd = _ffi.fdDup(fd)
rpmfd = gc(_ffi.fdDup(fd), _ffi.Fclose)

h = _ffi.ffi.new("Header*")
res = _ffi.rpmReadPackageFile(
Expand All @@ -133,4 +133,4 @@ def hdrFromFdno(self, fd):
# TODO: raise proper exceptions
assert res == _const.RPMRC_OK

return Header(_ffi.ffi.cast("Header", h[0]))
return Header(gc(_ffi.ffi.cast("Header", h[0]), _ffi.headerFree))

0 comments on commit c6a6b9a

Please sign in to comment.