当我在结构中编辑或打印一个字段时,我会收到有关内存泄漏的错误错误,但是如果我使用像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 = %dn", p);
printf("<DEBUG : xxxxxxset_intp_val>, val = %dn", val);
printf("<DEBUG : xxxxxxset_intp_val>, *p = %dn", *p);
printf("----------------------------------------------n");
}
void print_intp_val(uint32_t* p)
{
printf("----------------------------------------------n");
printf("<DEBUG : xxxxxxset_intp_val>, *p = %dn", *p);
printf("<DEBUG : xxxxxxset_intp_val>, p = %dn", 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.
尝试将%include "stdint.i"
添加到接口文件的顶部。