mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
fix(python): free allocated string pointers (#393)
* fix(python): free allocated string pointers * Update python/src/deltachat/cutil.py Co-Authored-By: holger krekel <holger@merlinux.eu> * Update cutil.py * probably the proper way to handle ffi.strings
This commit is contained in:
committed by
holger krekel
parent
6b2fe03d08
commit
8c10aa287c
@@ -34,13 +34,14 @@ def py_dc_callback(ctx, evt, data1, data2):
|
|||||||
if data1 and event_sig_types & 1:
|
if data1 and event_sig_types & 1:
|
||||||
data1 = ffi.string(ffi.cast('char*', data1)).decode("utf8")
|
data1 = ffi.string(ffi.cast('char*', data1)).decode("utf8")
|
||||||
if data2 and event_sig_types & 2:
|
if data2 and event_sig_types & 2:
|
||||||
|
data2 = ffi.string(ffi.cast('char*', data2)).decode("utf8")
|
||||||
try:
|
try:
|
||||||
data2 = ffi.string(ffi.cast('char*', data2)).decode("utf8")
|
if isinstance(data2, bytes):
|
||||||
|
data2 = data2.decode("utf8")
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
# XXX ignoring this error is not quite correct but for now
|
# XXX ignoring the decode error is not quite correct but for now
|
||||||
# i don't want to hunt down encoding problems in the c lib
|
# i don't want to hunt down encoding problems in the c lib
|
||||||
data2 = ffi.string(ffi.cast('char*', data2))
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = callback(ctx, evt_name, data1, data2)
|
ret = callback(ctx, evt_name, data1, data2)
|
||||||
if ret is None:
|
if ret is None:
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ def iter_array(dc_array_t, constructor):
|
|||||||
|
|
||||||
|
|
||||||
def from_dc_charpointer(obj):
|
def from_dc_charpointer(obj):
|
||||||
return ffi.string(obj).decode("utf8")
|
return ffi.string(ffi.gc(obj, lib.dc_str_unref)).decode("utf8")
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class Message(object):
|
|||||||
import email.parser
|
import email.parser
|
||||||
mime_headers = lib.dc_get_mime_headers(self._dc_context, self.id)
|
mime_headers = lib.dc_get_mime_headers(self._dc_context, self.id)
|
||||||
if mime_headers:
|
if mime_headers:
|
||||||
s = ffi.string(mime_headers)
|
s = ffi.string(ffi.gc(mime_headers, lib.dc_str_unref))
|
||||||
if isinstance(s, bytes):
|
if isinstance(s, bytes):
|
||||||
s = s.decode("ascii")
|
s = s.decode("ascii")
|
||||||
return email.message_from_string(s)
|
return email.message_from_string(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user