I just had one question about "fd_sess_handler_create" function in freeDiameter library.
Well, in test_app extension, there is a ta_cli_init function to initialize the client procedure, this block was compiled fine when the code was in C :
int ta_cli_init(void)
{
CHECK_FCT( fd_sess_handler_create(&ta_cli_reg, (void*)free, NULL, NULL) );
CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.cli", ta_cli_test_message ) );
return 0;
}
However, as soon as i changed the code to C++ , the compiler started to nagging about "cleanup" parameter (second param) that I had to change the code to make the it compiled:
void sess_handler_free(struct sess_state * state, os0_t sid, void * opaque)
{
}
int ta_cli_init(void)
{
CHECK_FCT( fd_sess_handler_create(&ta_cli_reg, &sess_handler_free, NULL, NULL) );
CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "ocs_app.cli", ta_cli_test_message ) );
return 0;
}
The code is now can be compiled, but because i wasnt sure about cleanup context, as you see i left it empty.
Could you plz explain to me what exactly should be cleaned up in my custom sess_handler_free function body ?
The
sess_handler_free
needs to free offstruct sess_state
plus any additional data structures your code has appended to it.If you don't have any additional data structures, you should just use be able to make
sess_handler_free
callfree(state)
. (Passing the free function directly is another way of doing this.)If you do have additional data structures, you need to find them from the
struct sess_state
and free them off usingdelete
if they were created usingnew
orfree
if they were created usingmalloc
.See
diameap_cli_sess_cleanup
as an example implementation - notice that it checks formethodData
,user.password
anduser.userid
fields and frees them off if present, before freeing thestruct sess_state
itself - this extension allocated these fields, so it is responsible for freeing them.