何时将python池freeblock分配为0xffffffff
开发Python C模块时,我遇到了Python分割故障。 调试后,事实证明,使用的池电流之一的FreeBlock设置为0xffffffff。
核心转储GDB帧:
(gdb) frame 0
#0 Py0bject_Malloc (nbytes=53) at../Objects/obmalloc.c:837
837 in ../Objects/obmalloc.c
(gdb) p bp
$6 = (block *) Oxffffffffffffffff <error: Cannot access memory at address Oxffffffffffffffff>
相对代码:
void *PyObject_Malloc(size_t nbytes) {
...
/*
* This implicitly redirects malloc(0).
*/
if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) {
LOCK();
/*
* Most frequent paths first
*/
size = (uint)(nbytes - 1) >> ALIGNMENT_SHIFT;
pool = usedpools[size + size];
if (pool != pool->nextpool) {
/*
* There is a used pool for this size class.
* Pick up the head block of its free list.
*/
++pool->ref.count;
bp = pool->freeblock;
assert(bp != NULL);
if ((pool->freeblock = *(block **)bp) != NULL) {
UNLOCK();
return (void *)bp;
}
...
}
A上面显示的是,它选择了池的FreeBlock(BP)
指向BP为0xffffffffff的值,这违反了我们对Python内存管理的认知。
因此,问题是,何时何时和为什么使用0xffffffff分配了FreeBlock指针?
I have met a Python Segmentation fault when developoing a python c module.
After debugging, it turns out that one of the pools current using has freeblock set to be 0xffffffff.
Core Dump gdb frames:
(gdb) frame 0
#0 Py0bject_Malloc (nbytes=53) at../Objects/obmalloc.c:837
837 in ../Objects/obmalloc.c
(gdb) p bp
$6 = (block *) Oxffffffffffffffff <error: Cannot access memory at address Oxffffffffffffffff>
for Better colored text, still provide gdb screen shots here.
Relative code:
void *PyObject_Malloc(size_t nbytes) {
...
/*
* This implicitly redirects malloc(0).
*/
if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) {
LOCK();
/*
* Most frequent paths first
*/
size = (uint)(nbytes - 1) >> ALIGNMENT_SHIFT;
pool = usedpools[size + size];
if (pool != pool->nextpool) {
/*
* There is a used pool for this size class.
* Pick up the head block of its free list.
*/
++pool->ref.count;
bp = pool->freeblock;
assert(bp != NULL);
if ((pool->freeblock = *(block **)bp) != NULL) {
UNLOCK();
return (void *)bp;
}
...
}
A above have shown, it pick value that pool's freeblock(bp)
point to while bp is 0xffffffff which violates our cognization to python memory management.
So the question is, when and why, would the freeblock pointer have been assigned with 0xffffffff?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我尚未正确使用GIL,并且触发了多线程错误的某个地方。然后,自由布的价值是错误的。
It turns out that i have not use gil properly, and somewhere multithreading error has been triggered. Then the freeblock's value has been wrong.