On Mon, Aug 15, 2005 at 10:14:14AM +0100, Dave Shield wrote:
> On Mon, 2005-08-15 at 11:03 +0200, Yegor Yefremov wrote:
> > Snmpv3_local_snmpEngineTime() gives a difference between start time and
> > now in seconds. It means when you change the year you have too big
> > difference. But actually one wants to know the time difference from
> > system start (snmpv3 engine start time).
> >
> > So I defined following function in system.c (and added a prototype to
> > system.h):
> >
> > long get_uptime_in_sec(void)
> > {
> > struct sysinfo *info =
> > (struct sysinfo*)malloc(sizeof(struct sysinfo));
> >
> > if(sysinfo(info) < 0)
> > {
> > perror("Getting uptime");
> > return -1;
> > }
> >
> > return info->uptime;
> > }
>
> Two comments/questions:
>
> a) Doesn't this introduce a memory leak?
> You appear to be allocating new memory every time that
> 'get_uptime_in_sec' is called, and never releasing it.
Also, my fist reaction was why the sysinfo structure is heap allocated in the
first place, why not just place it on the stack?
> b) What architecture(s) have you tried this with?
> How portable is the 'sysinfo' call?
>From the man page for sysinfo(2)
CONFORMING TO
This function is Linux-specific, and should not be used in programs
intended to be portable.
/MF
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders