I’m working on integrating rLog with our code base, and I’m noticing a problem on Windows that I don’t have on linux. In a header file I have a static variable that gives me a “verbose” logging channel (one up from debug basically), defined thusly:
static RLogChannel *rlog_verbose = DEF_CHANNEL("verbose", Log_Debug);
There’s no problem with this on Linux, but on Windows I get an error as soon as the application starts.
I’ve tracked it down to this line in the rLog library:
RLogChannel *rlog::GetComponentChannel(const char *component, const char* path, LogLevel levl) {
...
if(!gRootChannel)
gRootChannel = new RLogChannel( "", level );
...
}
The problem is that the call to new is returning a NULL pointer, which goes unchecked
and the program promptly crashes when it’s accessed. Are there rules related to allocating memory in a global context on Windows that I’m not away of?
Edit: I’m pretty sure this must be something related to the order of initialization of static objects. I wanted to be sure that I wasn’t missing something obvious re: memory allocation on Windows. Thanks all!
are you sure its returning null. It might be the whole static initializer thing. The order of static initializer invocations is not defined from file to file. If you have static code that is using rlog_verbose then gRootCHannel might well be NULL simply because the initializer hasn’t been called yet.