Skip to content

Commit

Permalink
fix lib_wwqLyParse memory free bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Dec 26, 2017
1 parent 9f14126 commit 2450ac6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
15 changes: 12 additions & 3 deletions wwqLyParse/lib/lib_wwqLyParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def init_lib():
lib_wwqLyParse = ctypes.cdll.LoadLibrary(get_real_path("./wwqLyParse64.dll"))
else:
lib_wwqLyParse = ctypes.cdll.LoadLibrary(get_real_path("./wwqLyParse32.dll"))
lib_wwqLyParse.parse.argtypes = [ctypes.c_char_p, ctypes.c_int,
ctypes.POINTER(ctypes.POINTER(ctypes.c_char)),
ctypes.POINTER(ctypes.c_int)]
lib_wwqLyParse.get_uuid.restype = ctypes.c_char_p
lib_wwqLyParse.get_name.restype = ctypes.c_char_p
logging.debug("successful load lib_wwqLyParse %s" % lib_wwqLyParse)
Expand All @@ -24,6 +27,12 @@ def init_lib():

def lib_parse(byte_str: bytes):
length = len(byte_str)
p = ctypes.create_string_buffer(byte_str, length)
lib_wwqLyParse.parse(p, length)
return p.raw
result_length = ctypes.c_int()
result_p = ctypes.POINTER(ctypes.c_char)()
# p = ctypes.create_string_buffer(byte_str, length)
p = ctypes.c_char_p(byte_str)
lib_wwqLyParse.parse(p, length, ctypes.byref(result_p), ctypes.byref(result_length))
result_arr = ctypes.cast(result_p, ctypes.POINTER(ctypes.c_char * result_length.value)).contents
result = b''.join(result_arr)
lib_wwqLyParse.free_str(result_p)
return result
2 changes: 1 addition & 1 deletion wwqLyParse/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
version = {
'port_version': "0.5.0",
'type': 'parse',
'version': '1.1.8',
'version': '1.1.9',
'uuid': '{C35B9DFC-559F-49E2-B80B-79B66EC77471}',
'filter': [],
'name': 'WWQ猎影解析插件',
Expand Down
22 changes: 15 additions & 7 deletions wwqLyParse/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_real_path(abstract_path):

need_close = True
if __name__ == '__main__':
CONFIG["port"] = 8000
CONFIG["port"] = 8005
else:
try:
with open(get_real_path('../../../ver.txt')) as f:
Expand Down Expand Up @@ -111,6 +111,9 @@ def init_lib():
lib_wwqLyParse = ctypes.cdll.LoadLibrary(get_real_path("./wwqLyParse64.dll"))
else:
lib_wwqLyParse = ctypes.cdll.LoadLibrary(get_real_path("./wwqLyParse32.dll"))
lib_wwqLyParse.parse.argtypes = [ctypes.c_char_p, ctypes.c_int,
ctypes.POINTER(ctypes.POINTER(ctypes.c_char)),
ctypes.POINTER(ctypes.c_int)]
lib_wwqLyParse.get_uuid.restype = ctypes.c_char_p
lib_wwqLyParse.get_name.restype = ctypes.c_char_p
assert lib_wwqLyParse.get_uuid().decode() == CONFIG["uuid"]
Expand All @@ -121,9 +124,15 @@ def init_lib():

def lib_parse(byte_str: bytes):
length = len(byte_str)
p = ctypes.create_string_buffer(byte_str, length)
lib_wwqLyParse.parse(p, length)
return p.raw
result_length = ctypes.c_int()
result_p = ctypes.POINTER(ctypes.c_char)()
# p = ctypes.create_string_buffer(byte_str, length)
p = ctypes.c_char_p(byte_str)
lib_wwqLyParse.parse(p, length, ctypes.byref(result_p), ctypes.byref(result_length))
result_arr = ctypes.cast(result_p, ctypes.POINTER(ctypes.c_char * result_length.value)).contents
result = b''.join(result_arr)
lib_wwqLyParse.free_str(result_p)
return result


def make_python():
Expand Down Expand Up @@ -409,14 +418,13 @@ def main():
# debug(Parse('http://www.iqiyi.com/v_19rrl8pmn8.html',"formats",parsers_name=["IQiYiParser"]))
# debug(Parse('http://www.iqiyi.com/v_19rrl8pmn8.html',"formats",parsers_name=["PVideoParser"]))
# debug(Parse('http://www.iqiyi.com/v_19rrl8pmn8.html'))
# debug(ParseURL("http://www.iqiyi.com/v_19rrl8pmn8.html","2.0@PVideoParser"))
# #debug(ParseURL("http://www.iqiyi.com/v_19rrl8pmn8.html","fullhd@IQiYiParser"))
# debug(ParseURL("http://www.iqiyi.com/v_19rrl8pmn8.html", "1080P-H264-S@IQiYiParser"))
# debug(Parse('http://v.pptv.com/show/NWR29Yzj2hh7ibWE.html?rcc_src=S1'))
# debug(Parse('http://www.bilibili.com/video/av2557971/')) #don't support
# debug(Parse('http://v.baidu.com/link?url=dm_10tBNoD-LLAMb79CB_p0kxozuoJcW0SiN3eycdo6CdO3GZgQm26uOzZh9fqcNSWZmz9aU9YYCCfT0NmZoGfEMoznyHhz3st-QvlOeyArYdIbhzBbdIrmntA4h1HsSampAs4Z3c17r_exztVgUuHZqChPeZZQ4tlmM5&page=tvplaydetail&vfm=bdvtx&frp=v.baidu.com%2Ftv_intro%2F&bl=jp_video',"formats"))
# debug(Parse('http://www.hunantv.com/v/1/291976/c/3137384.html',parsers_name=["IMgTVParser"]))
# debug(ParseURL('http://www.mgtv.com/v/1/291976/c/3137384.html',"3@MgTVParser"))
debug(Parse('http://v.youku.com/v_show/id_XMTYxODUxOTEyNA==.html?f=27502474'))
# debug(Parse('http://v.youku.com/v_show/id_XMTYxODUxOTEyNA==.html?f=27502474'))
# debug(Parse('http://v.qq.com/cover/y/yxpn9yol52go2i6.html?vid=f0141icyptp'))
# debug(ParseURL('http://v.qq.com/cover/y/yxpn9yol52go2i6.html?vid=f0141icyptp','4_1080p____-1x-1_2521.9kbps_09:35.240_1_mp4_@LypPvParser'))
# Cleanup()
Expand Down
Binary file modified wwqLyParse/wwqLyParse32.dll
Binary file not shown.
Binary file modified wwqLyParse/wwqLyParse64.dll
Binary file not shown.

0 comments on commit 2450ac6

Please sign in to comment.