Segmentation fault when returning a sequence CORBA C++ Server Java Client

陌路散爱 提交于 2019-12-11 20:15:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!