Discussion:
AW: [omniORB] String handling problem with VC7.1
Ecker Severin
2007-03-23 12:56:09 UTC
Permalink
Hi all,
I suspect that you are using non-debug and debug versions of MS C
runtime library: one is used by the omniORB and the other is used by
your application.
I've checked the libs and to me they seem to be the correct ones
(meaning I'm using the debug libs for my debug code)
I would say,the problem is, when you assign the constant pointer to
var.id, var assumes ownership of the memory pointed to, and it will
attempt to free it, when the variable releases ownership of it.
CosNaming::Name behaves like _var types in that respect, and your
runtime is quite right to complain about freeing string constants.
I doubt that because the weird thing is in
static inline void free(char* s) {
if (s && s != empty_string) delete[] s;
}

s indeed does have the same value as empty_string according to the
debugger and using the exact same code outside of the lib in my
application it does work fine. It just fails when code runs through this
function in the corba lib ;/

cheers,
severin
Matej Kenda
2007-03-23 13:20:38 UTC
Permalink
Post by Ecker Severin
Hi all,
I suspect that you are using non-debug and debug versions of MS C
runtime library: one is used by the omniORB and the other is used by
your application.
I've checked the libs and to me they seem to be the correct ones
(meaning I'm using the debug libs for my debug code)
Do you also use debug version of omniORB? If not, then omniORB
libraries are linked with non-debug C runtime library.

Regards,

Matej
--
Matej Kenda, Senior Software Engineer
HERMES SoftLab d.d. (www.hermes-softlab.com), Slovenia
Ecker Severin
2007-03-23 17:32:11 UTC
Permalink
Hi,

Just if you want to know I've got it solved.
I was missing a preprocessor which screwed up badly ;/

Thanks everyone for your support!

Cheers,
severin
Brian Neal
2007-03-23 18:05:18 UTC
Permalink
I'm wondering if I'm just using CORBA in an incorrect way or if there
really is an issue but whenever I try to use the following code I get an
CosNaming::Name var;
var.length(1);
var[0].id = (const char*)"test";
What you are doing seems fine from a CORBA perspective. However I just
wanted to point out that on a modern, conforming C++ compiler, the
const char* cast is not necessary. Under the *old* rules of C++, a
literal of the form "test" would have type char*, so ownership would
have been taken by var[0].id, and the destructor would have tried to
free it (bad). Under modern C++, a literal string like "test" has the
type const char* already, so var[0].id will do a deep copy
(essentially calling string_dup() for you). I have used code like the
above, without the cast, many times on omniORB and gcc without any
problems. I strongly suspect VC7.1 also conforms in this manner, and
the problem you are seeing must be something else.

You can test your compiler's conformance in this regard with a sample
C++ program like this one:

#include <iostream>
#include <ostream>

void f(char *s)
{
std::cout << "non-const: " << s << std::endl;
}

void f(const char* s)
{
std::cout << "const: " << s << std::endl;
}

int main()
{
f("test string");
return 0;
}

Regards,
BN

Loading...