简体   繁体   中英

swig/python detected a memory leak of type 'uint32_t *', no destructor found

When I edit or print a field in structure I get the mentioned error about memory leak, but if I work with simple variable like xx below there is no memory leak. Why is that ?

file 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)

file: 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");
    }

output:

----------------------------------------------
<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"添加到界面文件的顶部。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM