comparison extensions/dbg_rt/dbg_rt.c @ 1545:3a40bd55ee74

dbg_rt: fix memory leak
author Thomas Klausner <tk@giga.or.at>
date Mon, 15 Jun 2020 20:32:03 +0200
parents 581bbd48524a
children 566bb46cc73f
comparison
equal deleted inserted replaced
1544:7bad8025e69d 1545:3a40bd55ee74
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * 32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
34 *********************************************************************************************************/ 34 *********************************************************************************************************/
35 35
36 /* 36 /*
37 * Debug-only extension for routing module; 37 * Debug-only extension for routing module;
38 * displays state information at the end of routing information process. 38 * displays state information at the end of routing information process.
39 */ 39 */
40 #include <freeDiameter/extension.h> 40 #include <freeDiameter/extension.h>
41 41
42 static struct fd_rt_fwd_hdl * fwd_hdl = NULL; 42 static struct fd_rt_fwd_hdl * fwd_hdl = NULL;
45 /* Proxying debug callback */ 45 /* Proxying debug callback */
46 static int dbgrt_fwd_cb(void * cbdata, struct msg ** msg) 46 static int dbgrt_fwd_cb(void * cbdata, struct msg ** msg)
47 { 47 {
48 char * buf = NULL; size_t buflen; 48 char * buf = NULL; size_t buflen;
49 TRACE_ENTRY("%p %p", cbdata, msg); 49 TRACE_ENTRY("%p %p", cbdata, msg);
50 50
51 LOG_D("[dbg_rt] FWD routing message: %p", msg ? *msg : NULL); 51 LOG_D("[dbg_rt] FWD routing message: %p", msg ? *msg : NULL);
52 if (msg) { 52 if (msg) {
53 CHECK_MALLOC( fd_msg_dump_treeview(&buf, &buflen, NULL, *msg, NULL, 0, 1) ); 53 CHECK_MALLOC( fd_msg_dump_treeview(&buf, &buflen, NULL, *msg, NULL, 0, 1) );
54 LOG_D("%s", buf); 54 LOG_D("%s", buf);
55 } 55 }
61 static int dbgrt_out_cb(void * cbdata, struct msg ** pmsg, struct fd_list * candidates) 61 static int dbgrt_out_cb(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
62 { 62 {
63 struct fd_list * li; 63 struct fd_list * li;
64 struct msg * msg = *pmsg; 64 struct msg * msg = *pmsg;
65 char * buf = NULL; size_t buflen; 65 char * buf = NULL; size_t buflen;
66 66
67 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); 67 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
68 68
69 LOG_D("[dbg_rt] OUT routing message: %p", msg); 69 LOG_D("[dbg_rt] OUT routing message: %p", msg);
70 CHECK_MALLOC( fd_msg_dump_treeview(&buf, &buflen, NULL, msg, NULL, 0, 1) ); 70 CHECK_MALLOC( fd_msg_dump_treeview(&buf, &buflen, NULL, msg, NULL, 0, 1) );
71 LOG_D("%s", buf); 71 LOG_D("%s", buf);
72 free(buf);
72 LOG_D("[dbg_rt] Current list of candidates (%p): (score - id)", msg); 73 LOG_D("[dbg_rt] Current list of candidates (%p): (score - id)", msg);
73 74
74 for (li = candidates->next; li != candidates; li = li->next) { 75 for (li = candidates->next; li != candidates; li = li->next) {
75 struct rtd_candidate *c = (struct rtd_candidate *) li; 76 struct rtd_candidate *c = (struct rtd_candidate *) li;
76 LOG_D("[dbg_rt] %d -\t%s", c->score, c->diamid); 77 LOG_D("[dbg_rt] %d -\t%s", c->score, c->diamid);
77 } 78 }
78 79
79 return 0; 80 return 0;
80 } 81 }
81 82
82 /* Register the callbacks to the daemon */ 83 /* Register the callbacks to the daemon */
83 static int dbgrt_main(char * conffile) 84 static int dbgrt_main(char * conffile)
84 { 85 {
85 TRACE_ENTRY("%p", conffile); 86 TRACE_ENTRY("%p", conffile);
86 87
87 CHECK_FCT( fd_rt_fwd_register ( dbgrt_fwd_cb, NULL, RT_FWD_ALL, &fwd_hdl ) ); 88 CHECK_FCT( fd_rt_fwd_register ( dbgrt_fwd_cb, NULL, RT_FWD_ALL, &fwd_hdl ) );
88 CHECK_FCT( fd_rt_out_register ( dbgrt_out_cb, NULL, -1 /* so that it is called late */, &out_hdl ) ); 89 CHECK_FCT( fd_rt_out_register ( dbgrt_out_cb, NULL, -1 /* so that it is called late */, &out_hdl ) );
89 90
90 return 0; 91 return 0;
91 } 92 }
92 93
93 /* Cleanup the callbacks */ 94 /* Cleanup the callbacks */
94 void fd_ext_fini(void) 95 void fd_ext_fini(void)
95 { 96 {
96 TRACE_ENTRY(); 97 TRACE_ENTRY();
97 98
98 /* Unregister the modules */ 99 /* Unregister the modules */
99 CHECK_FCT_DO( fd_rt_fwd_unregister ( fwd_hdl, NULL ), /* continue */ ); 100 CHECK_FCT_DO( fd_rt_fwd_unregister ( fwd_hdl, NULL ), /* continue */ );
100 CHECK_FCT_DO( fd_rt_out_unregister ( out_hdl, NULL ), /* continue */ ); 101 CHECK_FCT_DO( fd_rt_out_unregister ( out_hdl, NULL ), /* continue */ );
101 102
102 return ; 103 return ;
103 } 104 }
104 105
105 /* Define the entry point function */ 106 /* Define the entry point function */
106 EXTENSION_ENTRY("dbg_rt", dbgrt_main); 107 EXTENSION_ENTRY("dbg_rt", dbgrt_main);
"Welcome to our mercurial repository"