Skip to content

Commit

Permalink
Fix memory leak in vcf.raw_header (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjeffery authored Sep 21, 2023
1 parent 7e1fdc9 commit e8281cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions cyvcf2/cyvcf2.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cdef extern from "htslib/kstring.h":
char *s;

char *ks_release(kstring_t *s)
void ks_free(kstring_t *s)

cdef extern from "htslib/hfile.h":
ctypedef struct hFILE:
Expand Down
15 changes: 9 additions & 6 deletions cyvcf2/cyvcf2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,15 @@ cdef class VCF(HTSFile):
return [str(self.hdr.samples[i].decode('utf-8')) for i in range(self.n_samples)]

property raw_header:
"string of the raw header from the VCF"
def __get__(self):
cdef kstring_t s
s.s, s.l, s.m = NULL, 0, 0
bcf_hdr_format(self.hdr, 0, &s)
return from_bytes(s.s)
"string of the raw header from the VCF"
def __get__(self):
cdef kstring_t s
s.s, s.l, s.m = NULL, 0, 0
bcf_hdr_format(self.hdr, 0, &s)

python_str = str(from_bytes(s.s))
ks_free(&s)
return python_str

property seqlens:
"list of chromosome lengths, if defined in the VCF header"
Expand Down

0 comments on commit e8281cc

Please sign in to comment.