Free or not to free

Free or not to free

Post by Subhabrata Biswa » Sat, 19 Dec 1998 04:00:00



Hi,

Do you have to free the struct tm* returned by gmtime() or
localtime() ? In other words, do these calls reuse the same
pointer (or variable) or do they allocate a new pointer for
every call ?

Thanks in advance,

-- Subhabrata Biswas

-----------------------------------------------
The NOTREQD in my email address is not required
-----------------------------------------------

 
 
 

Free or not to free

Post by Aaron Cra » Sun, 20 Dec 1998 04:00:00




> Do you have to free the struct tm* returned by gmtime() or localtime()?

No.  An easy way to remember this is that no standard ISO C library
functions allocate memory (with the obvious exceptions of malloc, realloc,
calloc).

Quote:> In other words, do these calls reuse the same pointer (or variable) or do
> they allocate a new pointer for every call?

It's not your place to know what they do internally, but it's true that most
implementations will use the obvious implementation of having them return a
pointer to a static block of memory.  An implementation is at liberty to
play funny games though; for example, it might reasonably return a pointer
to a thread-private block of memory.

--


 
 
 

Free or not to free

Post by Lawrence Kir » Sun, 20 Dec 1998 04:00:00




Quote:>Hi,

>Do you have to free the struct tm* returned by gmtime() or
>localtime() ?

No, the standard defines that these return a pointer to a static buffer
so attempting to pass these pointers to free() would be a serious error.
Also note that a subsequent call to one of these functions could therefore
overwrite the data from a previous call.

Quote:>In other words, do these calls reuse the same
>pointer (or variable) or do they allocate a new pointer for
>every call ?

No standard C library function except malloc/calloc/realloc allocates
memory that you have to free. Note that strdup() does but it isn't a
standard C library function.

--
-----------------------------------------


-----------------------------------------

 
 
 

1. Solaris 2.4 panic: free: freeing free block

I recently (< a week ago)  installed all the "recommended" patches for
a Solaris 2.4 system and since then the system has been crashing
regularly with a "panic: free: freeing free block" message.

I searched the readme's on all the Sun patches I could find but
couldn't find a patch for Solaris 2.4 that mentioned this message.  It
IS mentioned in patches for other versions of the OS, but not for
SunOS.

Anyone have an idea of a way to fix it?  Should I just start backing
out all the patches I just installed until it starts working again?

The particular file system involved is a Solstice DiskSuite
meta-device, but I don't think that is the problem:  it was working
fine before the patches and I didn't install any DiskSuite patches.

The only other unusual thing in syslog is messages that say:

WARNING: md: logging device: /dev/md/dsk/d11 changed state to Hard Error
WARNING: md: logging device: /dev/md/dsk/d11 changed state to Okay

These show up after as the system reboots but I suspect they don't
indicate a real (hardware) problem, but I could be wrong.  There are
no other errors or unusual messages anywhere that I can find.

BTW, this is a Sun Sparc 5 system.

Thanks,

Jim

2. To start XWindow without a mouse ----> keyboard hangs

3. FREE E-MAIL, FREE DISK SPACE, FREE UNIX ACCOUNT

4. how to see terminals outside of X in X.

5. FREE E-MAIL ACCOUNT, FREE DISK SPACE, FREE UNIX ACCOUNT.

6. su causes ppp dialup!

7. How to enable napster when using ipchains DENY ALL policy ?

8. FREE E-MAIL ACCOUNT, FREE DISK SPACE, FREE UNIX ACCOUNT

9. FREE EMAIL ACCOUNT FREE DISK SPACE FREE UNIX ACCOUNT

10. Free as in 'Freedom' not 'Free Beer'

11. free or not to free...