Hi, Colin,
Thanks. I just finished testing my own patch. It's a hack, but it works.
I changed su_time and su_nanocounter to use clock_gettime(CLOCK_MONOTONIC,
&ts),
if available (see below). Your code is a more portable workaround,
though, because
it doesn't rely on the availability of clock_gettime and CLOCK_MONOTONIC.
But, I think the proper way to fix this is to change all the timer code in
Sofia
to use monotonic time instead of NTP time. That's a much bigger job, and
I'm guessing that's why it hasn't been addressed yet. I looked at doing
it myself, but found some of the code to be somewhat less than readable.
So, for now at least, I've left it to someone with more experience with
that code.
Thanks anyway for your response, Colin. And thanks for your original
posting,
which was especially helpful.
Cheers.
--JT
Index: src/sofia-sip/libsofia-sip-ua/su/su_time.c
===================================================================
--- src/sofia-sip/libsofia-sip-ua/su/su_time.c
+++ src/sofia-sip/libsofia-sip-ua/su/su_time.c
@@ -411,6 +411,11 @@
else if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp) >= 0)
cpu = CLOCK_PROCESS_CPUTIME_ID;
#endif
+#ifdef HAVE_CLOCK_MONOTONIC
+ else if (clock_gettime(CLOCK_MONOTONIC, &tp) >= 0) {
+ cpu = CLOCK_MONOTONIC;
+ }
+#endif
else if (clock_gettime(CLOCK_REALTIME, &tp) >= 0)
cpu = CLOCK_REALTIME;
else
Index: src/sofia-sip/libsofia-sip-ua/su/su_time0.c
===================================================================
--- src/sofia-sip/libsofia-sip-ua/su/su_time0.c
+++ src/sofia-sip/libsofia-sip-ua/su/su_time0.c
@@ -46,6 +46,10 @@
#include <time.h>
+#if HAVE_CLOCK_GETTIME
+#include <errno.h>
+#endif
+
#if HAVE_SYS_TIME_H
#include <sys/time.h> /* Get struct timeval */
#endif
@@ -78,6 +82,20 @@
*/
void su_time(su_time_t *tv)
{
+#if HAVE_CLOCK_GETTIME && HAVE_CLOCK_MONOTONIC
+ struct timespec ts;
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
+ {
+ tv->tv_sec = ts.tv_sec;
+ tv->tv_usec = ts.tv_nsec / 1000;
+ return;
+ }
+ else
+ {
+ SU_DEBUG_0(("clock_gettime failed: %d = %s.\n", errno,
strerror(errno)));
+ }
+#endif
+
#if HAVE_GETTIMEOFDAY
if (tv) {
gettimeofday((struct timeval *)tv, NULL);
Colin Whittaker <col...@occamnetworks.com>
10/30/2009 12:51 PM
To: Jen Chitty <jenchi...@vtech.ca>
cc: sofia-sip-devel@lists.sourceforge.net
Subject: Re: [Sofia-sip-devel] Memory leak in timeouts?
Hi Jen,
It doesn't appear this has been fixed yet.
My patch below should still work.
Colin..
Jen Chitty wrote:
Hi,
Did this ever get resolved?
We are running into this problem now under 1.12.10.
Once the bug is triggered by changing the system time while a call is in
progress, memory leaks on every SIP transaction.
Doing a nua_shutdown causes all the leaked memory to be released, but we
can't afford to do that whenever the time changes while a call is in
progress.
Any help on this would be greatly appreciated.
Thanks,
--JT
On Tue, Aug 5, 2008 at 7:30 PM, Colin Whittaker
<col...@oc...> wrote:
>
> I think the memory leaks are still there if the Time of Day gets updated
too
> far.
> It looks like su_monotime() was added, but the timers are not using it.
>
> I'm testing a fix that changes su_time() and forces it to be monotonic
much
> like the way the kernel does monotonic time.
> The time of day will be off for su_time() but it didn't seem to hurt
> anything.
> I think the better fix is to change all the calls to su_time() for
timers
> and call su_monotime() instead.
>
> Here is my code for the 1.12.6 version The function is su_time().,
>
> diff -r1.1 -r1.2
> 70a71,75
>> // attempt at making time monotonic
>> unsigned long prev_tv_sec = 0;
>> unsigned long prev_tv_usec = 0;
>> unsigned long mono_tv_sec_adj = 0;
>>
> 75a81,104
>> if ( prev_tv_sec &&
>> ( (tv->tv_sec > prev_tv_sec + 2) ||
>> (tv->tv_sec < prev_tv_sec) ) )
>> {
>> // Time warp.....(someone set the clock or we fell asleep
>> over 2 seconds.)
>> // fix up our monotonic so we are in the same second as last
>> time
>> unsigned long adj;
>>
>> adj = (prev_tv_sec - tv->tv_sec);
>>
>> // if we were futher along in the second jump to the next.
>> if ( prev_tv_usec > tv->tv_usec )
>> {
>> adj++;
>> }
>> SU_DEBUG_2(("Clock slip detected, %ld seconds. Previous
>> Monotonic adjustment %ld. Current %ld sec, %ld usec, Prev %ld sec %ld
usec",
>> adj, mono_tv_sec_adj, tv->tv_sec,
>> tv->tv_usec, prev_tv_sec, prev_tv_usec ));
>> mono_tv_sec_adj += adj;
>> }
>>
>> prev_tv_sec = tv->tv_sec;
>> prev_tv_usec = tv->tv_usec;
>> tv->tv_sec += mono_tv_sec_adj;
>>
>
> Colin..
>
> Fabio Margarido wrote:
>
> Hi there Pekka,
>
> back in April, I got this response to a question about an assertion
> regarding nta timers:
>
>
>
> The code calculating the timeouts has flawed logic, the problem shows
> up if the system clock is adjusted or the load is too high.
>
>
> I'd like to know if this issue has already been resolved in the darcs
> tree. I've noticed that when the system clock is adjusted sofia-sip
> apparently leaks memory.
> I'm still using 1.12.8 because of the other memory leaks in 1.12.9
> that have been reported to the list. Are those fixed too?
> Thanks.
>
> Fabio
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel