standard variadic functions allocate memory? 
Author Message
 standard variadic functions allocate memory?

I am trying to write a logging facility for handling error conditions,
which might include trashed stack, out of memory. Having trapped
the signal (prob SIGSEGV), I realize I won't be able to much before
exiting. The question is, can I do anything?

I would like to write an error message to the logging system,
which might be to stderr or to a file. I would like to use
vfprintf. Does this sound like a plausible endeavor? Has anyone
played around in this area? Hints? Pointers? Is it all
undefined? Platform specific? Am I sinning just by thinking
about it?

-bluejack

/* -------------------------------------------------------------- *\
    http://www.*-*-*.com/      ||     reviews of science fiction
                                ||     record of the writing life
\* -------------------------------------------------------------- */



Sat, 25 Sep 2004 13:33:30 GMT  
 standard variadic functions allocate memory?

Quote:

>I am trying to write a logging facility for handling error conditions,
>which might include trashed stack, out of memory. Having trapped
>the signal (prob SIGSEGV), I realize I won't be able to much before
>exiting. The question is, can I do anything?

>I would like to write an error message to the logging system,
>which might be to stderr or to a file. I would like to use
>vfprintf. Does this sound like a plausible endeavor? Has anyone
>played around in this area? Hints? Pointers? Is it all
>undefined? Platform specific? Am I sinning just by thinking
>about it?

You can do very little inside a signal handler to begin with without
invoking UB; you certainly can't call vfprintf(). Furthermore, with
SIGSEGV, you also aren't guaranteed that the program will behave in
any predictable way after the signal handler returns. In practice,
I've tried to do this and the result has sometimes been that my
program has gone into an infinite loop (SIGSEGV, signal handler
returns, SIGSEGV, signal handler returns ...).

It's probably better just to exit the program in the signal handler in
these cases.

Russ



Sat, 25 Sep 2004 13:57:18 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Variadic functions & possible memory leak

2. allocating memory in one function and freeing it with another function

3. allocating memory with functions

4. Allocating memory inside a function

5. allocating memory and processing thru function.

6. Do the string functions allocate memory?

7. getline function that allocates memory on-the-fly

8. allocate memory for function

9. allocate memory in a function

10. C functions that allocate memory

11. Freeing memory allocated inside a function

12. How to access memory allocated in function

 

 
Powered by phpBB® Forum Software