1. A xxx structure will be allocated inside the osip_xxx_init() related functions, but the xxx structure field space is not allocated, so only osip_free() can be called to release it later, but osip_xxx_free() cannot be called to release
such as:
osip_www_authenticate_t *www_auth;
osip_www_authenticate_init (&www_auth);
osip_www_authenticate_set_auth_type(www_auth, osip_strdup("Digest"));
osip_www_authenticate_set_algorithm_MD5(www_auth);
osip_www_authenticate_set_realm(www_auth, osip_strdup(realm));
/*
* Use www_auth related operations...
*/
/* www_auth should be freed after use */
osip_free(www_auth); /* correct*/
osip_www_authenticate_free(www_auth); /* wrong*/
2. Part of the dynamic allocation space in the osip_xxx_to_str() related functions, after use, record and call osip_free() to release the space,
such as:
char *str_www_auth = NULL;
osip_www_authenticate_to_str(www_auth, &str_www_auth);
osip_free(str_www_auth);
3. The related functions of osip_xxx_xxx_add will dynamically allocate memory, which must be released later by osip_xxx_xxx_free.
For example:
Error code 1:
osip_contact_t *contact = NULL;
osip_contact_init(&contact);
/* Internally, osip_xxx_xxx_init related functions will be called to apply for space*/
osip_contact_param_add(contact, "expires", "90");
/*
* Use contact related operations...
*/
/* There is no deep free space here, which will cause memory leaks */
osip_free(contact);
Correct code 2:
osip_contact_t *contact = NULL;
osip_contact_init(&contact);
osip_contact_param_add(contact, osip_strdup("expires"), osip_strdup("90"));
/*
* Use contact related operations...
*/
osip_contact_free(contact);
Fourth, call the eXosip_xxx_build_xxx function to generate the osip_message_t message structure first, and then call the osip_message_t message structure of the eXosip_xxx_send_xxx
function
. NULL;
eXosip_call_build_info (m_eXosip_context, s32DialogId, & Request);
osip_call_id_t * call_id = osip_message_get_call_id (Request);
String strCallID = osip_call_id_get_number (call_id);
osip_message_free (Request);
eXosip_call_terminate (m_eXosip_context, s32CallId, s32DialogId);
Fifth, there are two ways to change eXosip_xxx_build_xxx series The osip_message_t message header field generated inside the function,
such as:
Method 1:
osip_www_authenticate_t *www_auth;
osip_www_authenticate_init (&www_auth);
osip_www_authenticate_set_auth_type(www_auth, osip_strdup("Digest"));
osip_www_authenticate_set_algorithm_MD5(www_auth);
osip_www_authenticate_set_realm(www_auth, osip_strdup(realm));
/* Add the generated www_auth pointer space directly to the message header */
osip_list_add(&answer->www_authenticates, www_auth, -1);
方法2:
osip_www_authenticate_t *www_auth;
osip_www_authenticate_init (&www_auth);
osip_www_authenticate_set_auth_type(www_auth, osip_strdup("Digest"));
osip_www_authenticate_set_algorithm_MD5(www_auth);
osip_www_authenticate_set_realm(www_auth, 先osip_strdup(realm));
/* First call osip_xxx_to_str to convert to the corresponding string, and then call osip_message_set_xxx to change the header field, osip_message_set_xxx will allocate space inside */
char *str_www_auth = NULL;
osip_www_authenticate_to_str(www_auth, &str_www_auth);
osip_message_set_www_authenticate(answer, str_www_auth);
/* Pay attention to free space*/
osip_free(str_www_auth);
osip_www_authenticate_free(www_auth);