问题
I'm developing a project in which I need to implement a Chat server in C++ and Chat clients in Java using swing for implementing the GUI.
I'm having exactly this problem, implementing nearly the same project:
Segmentation fault CORBA C++
This is the part of my IDL where the problem is:
typedef sequence<ICliente> ListaClientes;
interface IServer
{
attribute ListaClientes lista;
void registrar_usuario (in ICliente cliente) raises (usuarioRegistrado);
IConversacion crear_conversacion (in ICliente cliente);
ListaClientes obtener_lista();
void dar_baja(in ICliente cliente);
};
And then the part of the code where I'm getting the segmentation fault is this one:
ListaClientes* Server_i::obtener_lista() {
return userList._retn();
}
Where:
ListaClientes_var userList=new ListaClientes(size);
Or:
ListaClientes* userList=new ListaClientes(size);
ListaClientes* Server_i::obtener_lista() {
return userList;
}
回答1:
It should be
ListaClientes* Server_i::obtener_lista() {
ListaClientes_var my_list = new ListaClientes(size);
my_list->length (size);
// Fill the elements in the newly created sequence by doing a duplicate of each object reference as it exists in the member variable
for(CORBA::ULong i=0;i<userList->length();i++){
my_list[i] = ICliente::_duplicate(userList[i]);
}
return my_list._retn();
}
来源:https://stackoverflow.com/questions/23762420/segmentation-fault-when-returning-a-sequence-corba-c-server-java-client