Barracuda Application Server C/C++ Reference
NO
Volatile/temporary memory used as name in a HttpDir/HttpPage

The name passed in as argument to a HttpDir/HttpPage object cannot be changed since the constructor only stores a pointer to the name. The virtual file system is designed to use as little memory as possible. Thus, the name passed in as argument to the HttpDir/HttpPage constructor is not copied; only the pointer reference is copied.

One would normally use constants as the name argument, but if you need to create a name dynamically, you can allocate space for the structure and the name as one piece as follows:

HttpDir* createDir(char* name)
{
HttpDir* dir = baMalloc(sizeof(HttpDir) + strlen(name) + 1);
if(dir)
{
char* ptr = (char*)(dir+1);
strcpy(ptr, name);
HttpDir_constructor(dir, ptr, 0);
}
return dir;
}
void * baMalloc(size_t size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
An instance of the HttpDir class, which is a collection of zero or more resources,...
Definition: HttpServer.h:2368

We use a HttpDir in the example above, but it also applies to a HttpPage, HttpResRdr, AuthenticateDir, EvDir or any class derived from HttpPage or HttpDir.