Python 3 : Crash with free(): corrupted unsorted chunks while reading file

标签 python python-3.x crash

我发现 Python 3 有以下奇怪的行为:

file = open(path, mode='rb').read()
file_ori = open(self.filePath, mode='rb').read()

m = hashlib.md5()
md5 = m.update(file)
md5 = m.hexdigest()

file = '0x'.encode('ascii') + binascii.hexlify(file)
file_ori = '0x'.encode('ascii') + binascii.hexlify(file_ori)

在这种情况下,我的应用程序迟早会崩溃,free():损坏的未排序 block

如果我将代码更改为:

file = open(path, mode='rb')
file_ori = open(self.filePath, mode='rb')

filecont = file.read()
file_oricont = file_ori.read()

m = hashlib.md5()
md5 = m.update(filecont)
md5 = m.hexdigest()

fileb = '0x'.encode('ascii') + binascii.hexlify(filecont)
fileb_ori = '0x'.encode('ascii') + binascii.hexlify(file_oricont)

应用程序运行没有问题。

我多次阅读文档,但找不到此行为的任何原因。有人可能对此了解更多吗?在我看来,Python 和垃圾收集有一个错误?

我用python3.4和python3.5进行了测试。

谢谢 曼努埃尔

最佳答案

第一个示例:在 python 2.7 中测试有效,并告诉我在哪一行发生错误

第二个例子:你必须知道当你调用 f.read() 时,文件中的光标到达文件末尾,因此另一个 f.read() 将不会输出任何内容,即 ''所以这两个例子是不同的

关于Python 3 : Crash with free(): corrupted unsorted chunks while reading file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40775619/

相关文章:

python - 为什么 '() is ()'和 '[] is []'返回False时 '{} is {}'返回True?

python - 将现有大写字母保留在字符串中

ios - 当 Storyboard 中存在冲突时 Xcode 崩溃

java - 远程 Swing 应用程序上的 "x connection host broken"

python - 解析 WAV 文件头

python - 如何使用python从git存储库下载单个文件

python - 加载预训练模型会抛出 ValueError : bad marshal data (unknown type code)

qt - QT Creator不想启动

python - Flask 和 WerkZeug 中的应用程序上下文和请求上下文是什么?

python - 谁能帮我用 python 读取不断更新的视频文件?