summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2008-10-21 14:29:47 +0000
committerNanang Izzuddin <nanang@teluu.com>2008-10-21 14:29:47 +0000
commita8cd80279624c8c4b1862fa541e009158d6e1981 (patch)
treec8781c20bc07bebfced5e09de886e42454bcfc23
parent5a3c7e0ea3131f8d81a282af4c3d93597c174684 (diff)
Ticket #558: Added srtp_deinit() function and registered this with pj_atexit().
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2353 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/src/pjmedia/transport_srtp.c22
-rw-r--r--third_party/srtp/include/srtp.h10
-rw-r--r--third_party/srtp/srtp/srtp.c9
3 files changed, 41 insertions, 0 deletions
diff --git a/pjmedia/src/pjmedia/transport_srtp.c b/pjmedia/src/pjmedia/transport_srtp.c
index 708aa77d..a3378923 100644
--- a/pjmedia/src/pjmedia/transport_srtp.c
+++ b/pjmedia/src/pjmedia/transport_srtp.c
@@ -260,6 +260,8 @@ const char* get_libsrtp_errstr(int err)
#endif
}
+static void pjmedia_srtp_deinit_lib(void);
+
static pj_status_t pjmedia_srtp_init_lib(void)
{
static pj_bool_t initialized = PJ_FALSE;
@@ -273,12 +275,32 @@ static pj_status_t pjmedia_srtp_init_lib(void)
return PJMEDIA_ERRNO_FROM_LIBSRTP(err);
}
+ if (pj_atexit(pjmedia_srtp_deinit_lib) != PJ_SUCCESS) {
+ /* There will be memory leak when it fails to schedule libsrtp
+ * deinitialization, however the memory leak could be harmless,
+ * since in modern OS's memory used by an application is released
+ * when the application terminates.
+ */
+ PJ_LOG(4, (THIS_FILE, "Failed to register libsrtp deinit."));
+ }
+
initialized = PJ_TRUE;
}
return PJ_SUCCESS;
}
+static void pjmedia_srtp_deinit_lib(void)
+{
+ err_status_t err;
+
+ err = srtp_deinit();
+ if (err != err_status_ok) {
+ PJ_LOG(4, (THIS_FILE, "Failed to deinitialize libsrtp: %s",
+ get_libsrtp_errstr(err)));
+ }
+}
+
static int get_crypto_idx(const pj_str_t* crypto_name)
{
int i;
diff --git a/third_party/srtp/include/srtp.h b/third_party/srtp/include/srtp.h
index bb9387f3..9fd3a575 100644
--- a/third_party/srtp/include/srtp.h
+++ b/third_party/srtp/include/srtp.h
@@ -258,6 +258,16 @@ err_status_t
srtp_init(void);
/**
+ * @brief srtp_deinit() deinitializes the srtp library.
+ *
+ * @warning This function @b must be called on quitting application or
+ * after srtp is no longer used.
+ */
+
+err_status_t
+srtp_deinit(void);
+
+/**
* @brief srtp_protect() is the Secure RTP sender-side packet processing
* function.
*
diff --git a/third_party/srtp/srtp/srtp.c b/third_party/srtp/srtp/srtp.c
index f2445558..b30f6d38 100644
--- a/third_party/srtp/srtp/srtp.c
+++ b/third_party/srtp/srtp/srtp.c
@@ -1102,6 +1102,15 @@ srtp_init() {
return err_status_ok;
}
+err_status_t
+srtp_deinit() {
+ err_status_t status;
+
+ status = crypto_kernel_shutdown();
+
+ return status;
+}
+
/*
* The following code is under consideration for removal. See
* SRTP_MAX_TRAILER_LEN