From: Wouter Wijngaards Date: Fri, 4 Sep 2009 14:14:54 +0000 (+0000) Subject: fix python memory leak. X-Git-Tag: release-1.4.0rc1~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=18e9cbb39f9abbcd75eb08b6abc2e9bcd031b137;p=thirdparty%2Funbound.git fix python memory leak. git-svn-id: file:///svn/unbound/trunk@1818 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index be0e01b23..c5d7c1b94 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -4,6 +4,7 @@ - do not call sphinx for documentation when python is disabled. - remove EV_PERSIST from libevent timeout code to make the code compatible with the libevent-2.0. Works with older libevent too. + - fix memory leak in python code. 3 September 2009: Wouter - Got a patch from Luca Bruno for libunbound support on windows to diff --git a/pythonmod/interface.i b/pythonmod/interface.i index 733430d29..2cc7bc9ae 100644 --- a/pythonmod/interface.i +++ b/pythonmod/interface.i @@ -779,7 +779,7 @@ int set_return_msg(struct module_qstate* qstate, { ldns_pkt* pkt = 0; ldns_status status; - ldns_rr_list* rr_list1 = 0,*rr_list2 = 0,*rr_list3 = 0,*rr_list4 = 0; + ldns_rr_list* rr_list = 0; ldns_buffer *qb = 0; int res = 1; @@ -790,14 +790,18 @@ int set_return_msg(struct module_qstate* qstate, if ((status != LDNS_STATUS_OK) || (pkt == 0)) return 0; - rr_list1 = createRRList(question, default_ttl); - if ((rr_list1) && (res)) res = ldns_pkt_push_rr_list(pkt, LDNS_SECTION_QUESTION, rr_list1); - rr_list2 = createRRList(answer, default_ttl); - if ((rr_list2) && (res)) res = ldns_pkt_push_rr_list(pkt, LDNS_SECTION_ANSWER, rr_list2); - rr_list3 = createRRList(authority, default_ttl); - if ((rr_list3) && (res)) res = ldns_pkt_push_rr_list(pkt, LDNS_SECTION_AUTHORITY, rr_list3); - rr_list4 = createRRList(additional, default_ttl); - if ((rr_list4) && (res)) res = ldns_pkt_push_rr_list(pkt, LDNS_SECTION_ADDITIONAL, rr_list4); + rr_list = createRRList(question, default_ttl); + if ((rr_list) && (res)) res = ldns_pkt_push_rr_list(pkt, LDNS_SECTION_QUESTION, rr_list); + ldns_rr_list_free(rr_list); + rr_list = createRRList(answer, default_ttl); + if ((rr_list) && (res)) res = ldns_pkt_push_rr_list(pkt, LDNS_SECTION_ANSWER, rr_list); + ldns_rr_list_free(rr_list); + rr_list = createRRList(authority, default_ttl); + if ((rr_list) && (res)) res = ldns_pkt_push_rr_list(pkt, LDNS_SECTION_AUTHORITY, rr_list); + ldns_rr_list_free(rr_list); + rr_list = createRRList(additional, default_ttl); + if ((rr_list) && (res)) res = ldns_pkt_push_rr_list(pkt, LDNS_SECTION_ADDITIONAL, rr_list); + ldns_rr_list_free(rr_list); if ((res) && ((qb = ldns_buffer_new(LDNS_MIN_BUFLEN)) == 0)) res = 0; if ((res) && (ldns_pkt2buffer_wire(qb, pkt) != LDNS_STATUS_OK)) res = 0; @@ -806,7 +810,7 @@ int set_return_msg(struct module_qstate* qstate, if (qb) ldns_buffer_free(qb); - ldns_pkt_free(pkt); //this function dealocates pkt as well as rr_lists + ldns_pkt_free(pkt); //this function dealocates pkt as well as rrs return res; } %} diff --git a/pythonmod/pythonmod.c b/pythonmod/pythonmod.c index 1568973f5..8d0a3fe9c 100644 --- a/pythonmod/pythonmod.c +++ b/pythonmod/pythonmod.c @@ -245,6 +245,8 @@ void pythonmod_deinit(struct module_env* env, int id) Py_Finalize(); } + pe->fname = NULL; + free(pe); /* Module is deallocated in Python */ env->modinfo[id] = NULL;