a issue with dup2

Hi,

i have in one program such a pice of code

................

static int old_stderr_handle = -1;
static int old_stdout_handle = -1;

log_handle = open(log_file_name,O_CREAT|O_RDWR,932);

old_stderr_handle = dup(STDERR_FILENO);

if (dup2(log_handle,STDERR_FILENO) < 0)
{
// print error
}

old_stdout_handle = dup(STDOUT_FILENO);

if (dup2(log_handle,STDOUT_FILENO) < 0)
{
// print error
}
.....

close ( old_stderr_handle );
close ( old_stdout_handle);

I build this program with Insure ( a tool ) after this i run it and in the log file
i found a message like

(Thread 0) **USER_ERROR**
>> if (dup2(log_handle,STDERR_FILENO) < 0)

Attempt to implicitly close Insure++ internal file descriptor 2 in dup2() ignored

Memory corrupted. Program may crash!!

Can somebody explain why? :frowning:

thanks.

This Insure program is expressly preventing you from using dup2 to redirect stderr. Perhaps it has its own methods of redirecting logfiles that you're supposed to use instead? Why it thinks memory is corrupted, I don't know, it may be unrelated to the redirection and provoked by code below it you didn't post.