Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
keep ref
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed May 20, 2024
1 parent 77bcb69 commit 40874a3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bencode_c/encode.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "object.h"
#include "stdio.h"
#include "string.h"

Expand Down Expand Up @@ -252,16 +253,19 @@ static HPy bencode(HPy self, HPy obj) {
// self is the module object

struct buffer *buf = newBuffer();
Py_IncRef(obj);

if (encodeAny(buf, obj)) {
freeBuffer(buf);
Py_DecRef(obj);
// error when encoding
return NULL;
}

HPy res = PyBytes_FromStringAndSize(buf->buf, buf->len);

freeBuffer(buf);
Py_DecRef(obj);

return res;
};

0 comments on commit 40874a3

Please sign in to comment.