swig/python 检测到“uint32_t *”类型的内存泄漏,没有找到析构函数
Posted
技术标签:
【中文标题】swig/python 检测到“uint32_t *”类型的内存泄漏,没有找到析构函数【英文标题】:swig/python detected a memory leak of type 'uint32_t *', no destructor found 【发布时间】:2016-12-04 14:07:01 【问题描述】:当我编辑或打印结构中的字段时,我得到了关于内存泄漏的上述错误,但如果我使用像下面的 xx 这样的简单变量,则没有内存泄漏。 这是为什么呢?
文件 rc_test.py:
import sys
import verbs_utils
import logging
logger = logging.basicConfig(level=logging.DEBUG)
class rc_pingpong():
def __init__(self, link_partner_hostname=None):
self.attr = verbs_utils.ibv_qp_attr()
self.init_to_rts()
def init_to_rts(self):
self.attr = verbs_utils.ibv_qp_attr()
logging.debug("<DEBUG: init_to_rts>, self.attr = ".format(self.attr))
logging.debug("<DEBUG: init_to_rts>, self.attr.path_mtu = ".format(self.attr.path_mtu))
logging.debug("<DEBUG: init_to_rts>, self.attr.min_rnr_timer = ".format(self.attr.min_rnr_timer))
logging.debug("<DEBUG: init_to_rts>, self.attr.qp_state = ".format(self.attr.qp_state))
logging.debug("<DEBUG: init_to_rts>, self.attr.port_num = ".format(self.attr.port_num))
xx = self.attr.dest_qp_num
verbs_utils.set_intp_val(xx , 7)
verbs_utils.print_intp_val(xx)
self.attr.dest_qp_num = xx
#logging.debug("<DEBUG: init_to_rts>, +++++++++ self.attr.dest_qp_num = ".format(self.attr.dest_qp_num))
verbs_utils.print_intp_val(self.attr.dest_qp_num)
verbs_utils.print_intp_val(self.attr.dest_qp_num)
文件:verbs_utils.c
struct ibv_qp_attr
uint32_t qkey;
uint32_t rq_psn;
uint32_t sq_psn;
uint32_t dest_qp_num;
;
void set_intp_val(uint32_t* p, int val)
*p = val;
printf("----------------------------------------------\n");
printf("<DEBUG : xxxxxxset_intp_val>, p = %d\n", p);
printf("<DEBUG : xxxxxxset_intp_val>, val = %d\n", val);
printf("<DEBUG : xxxxxxset_intp_val>, *p = %d\n", *p);
printf("----------------------------------------------\n");
void print_intp_val(uint32_t* p)
printf("----------------------------------------------\n");
printf("<DEBUG : xxxxxxset_intp_val>, *p = %d\n", *p);
printf("<DEBUG : xxxxxxset_intp_val>, p = %d\n", p);
printf("----------------------------------------------\n");
输出:
----------------------------------------------
<DEBUG : xxxxxxset_intp_val>, p = 8431360
<DEBUG : xxxxxxset_intp_val>, val = 7
<DEBUG : xxxxxxset_intp_val>, *p = 7
----------------------------------------------
----------------------------------------------
<DEBUG : xxxxxxset_intp_val>, *p = 7
<DEBUG : xxxxxxset_intp_val>, p = 8431360
----------------------------------------------
----------------------------------------------
<DEBUG : xxxxxxset_intp_val>, *p = 7
<DEBUG : xxxxxxset_intp_val>, p = 8967344
----------------------------------------------
swig/python detected a memory leak of type 'uint32_t *', no destructor found.
----------------------------------------------
<DEBUG : xxxxxxset_intp_val>, *p = 7
<DEBUG : xxxxxxset_intp_val>, p = 9753776
----------------------------------------------
swig/python detected a memory leak of type 'uint32_t *', no destructor found.
【问题讨论】:
【参考方案1】:尝试将%include "stdint.i"
添加到接口文件的顶部。
【讨论】:
以上是关于swig/python 检测到“uint32_t *”类型的内存泄漏,没有找到析构函数的主要内容,如果未能解决你的问题,请参考以下文章
从 uint8_t* 到 uint32_t 的无效转换 - 从 32 位架构迁移到 64 位架构时?