Bug 345 - CosNaming::NameComponent destructor causes crash
Summary: CosNaming::NameComponent destructor causes crash
Status: CLOSED
Alias: None
Product: TAO
Classification: Unclassified
Component: orbsvcs (show other bugs)
Version: 1.0
Hardware: x86 Windows NT
: P2 critical
Assignee: Marina Spivak
URL:
Depends on:
Blocks:
 
Reported: 1999-09-28 11:00 CDT by Mike Burkhart
Modified: 2000-12-03 22:08 CST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Burkhart 1999-09-28 11:00:38 CDT
Simply creating and destroying an instance of CosNaming::NameComponent causes a
program crash. The source code looks like this:

    CosNaming::NameComponent *name_component;
    name_component->id = "IpcManager";
    name_component->kind = "";
      .
      .
      .
    delete name_component;

The stack trace shows the crash is occuring in the destructor for NameComponent:

operator delete(void * 0x0043e76c) line 47 + 81 bytes
CORBA::string_free(char * 0x0043e76c) line 14 + 15 bytes
TAO_String_Manager::~TAO_String_Manager() line 37 + 11 bytes
CosNaming::NameComponent::~NameComponent() + 47 bytes
IpcServerObj::Connect(const char * 0x0107ae63, int 0x00000000) line 216
+ 76 bytes
ace_main_i(int 0x00000002, char * * 0x0107ae50) line 122 + 20 bytes
main(int 0x00000002, char * * 0x0107ae50) line 77 + 69 bytes
mainCRTStartup() line 338 + 17 bytes
KERNEL32! 77f1ba3c()
Comment 1 Ossama Othman 1999-09-28 15:10:59 CDT
This is related to the Naming Service.
Comment 2 Ossama Othman 1999-09-28 15:18:59 CDT
Oops.  orbsvcs, but Marina's neverthless.
Comment 3 Carlos O'Ryan 1999-09-28 15:44:59 CDT
Actually i believe this is a bug in the user's code, i have asked him to test a
change, my guess is that this bug is going into the NOT_A_BUG category.
Comment 4 Marina Spivak 1999-10-04 14:52:59 CDT
The problem is in the user's code: the right side of the assignment to a struct
member of type string should be either a const char * or dynamically allocated
string (i.e., char *), e.g.,
name_component->id = (const char *)"Ipc_Manager";
or
name_component->id = CORBA::string_dup ("IpcManager");

In the first case, since the item on the right side of assignment is const, a
copy of it is created and memory-managed by the struct.  In the second case,
struct takes ownership of the passed string, and will deallocate it when
necessary.

The reason name_component->id = "IpcManager"; doesn't work is because many
compilers treat literal string (e.g., "IpcManager") as a char*, not const char*!
So the struct takes ownership of the passed string literal without duplicating
it, and attempts to delete it in its destructor ;(
Comment 5 Mike Burkhart 1999-10-04 15:22:59 CDT
You guys were right on, the problem was my fault. Thank you for the quick
response.  Sorry to waste your time with my programming errors!
Comment 6 Marina Spivak 2000-12-03 22:08:06 CST
Not a bug.  Close.