Segmentation fault CORBA C++

青春壹個敷衍的年華 提交于 2020-01-06 08:27:28

问题


I am trying to build a CORBA application, which has the following IDL interface:

module Chat {
exception SesionNoIniciada{};
exception UsuarioNoRegistrado{};
exception ErrorServidor{};
exception SesionYaIniciada{};

interface Cliente{
    readonly attribute string nombre;

    oneway void nuevaSolicitudDeAmistad(in string c); //devuelve void, parametro string/char*
    oneway void actualizarListaAmigos();
    oneway void nuevoMensaje(in Cliente usuario, in string men);
};

typedef sequence<string> nombres;
typedef sequence<Cliente> clientes;

interface Servidor{
    nombres iniciarSesion(in Cliente usuario, in string pass) raises (UsuarioNoRegistrado, SesionYaIniciada);
    void cerrarSesion(in Cliente usuario, in string pass) raises (SesionNoIniciada);

    nombres getUsuariosRegistrados(in Cliente usuario, in string pass, in string nombre) raises (SesionNoIniciada);
    nombres getAmigos(in Cliente usuario, in string pass) raises (SesionNoIniciada);
    clientes getAmigosConectados(in Cliente usuario, in string pass) raises (SesionNoIniciada);
    void nuevaSolicitudDeAmistad(in Cliente amigo1, in string pass, in string amigo2) raises (UsuarioNoRegistrado, SesionNoIniciada);
    void aceptarSolicitudDeAmistad(in Cliente amigo1, in string pass, in string amigo2) raises (UsuarioNoRegistrado, SesionNoIniciada);
    void rechazarSolicitudDeAmistad(in Cliente amigo1, in string pass, in string amigo2) raises (UsuarioNoRegistrado, SesionNoIniciada);
    void eliminarAmistad(in Cliente amigo1, in string pass, in string amigo2) raises (UsuarioNoRegistrado, SesionNoIniciada);
};
};

The following method is giving me a segmentation fault in the return line:

nombres* Servidor_i::getAmigos(Cliente_ptr usuario, const char* pass){

vector<string> aux;
nombres_var result;
Cliente_ptr cliente;

try{
    aux=bd.listarAmigos(usuario->nombre()); //Gets names from DB (currently 0)
    result = new nombres(aux.size());
    for(int i=0; i<aux.size(); i++) //This for is not being executed, since size is 0
        result[i] = aux.at(i).c_str();
} catch(ErrorBD& e){
    throw ErrorServidor();
}
cout << "Ending" << endl;
return result._retn();
}

I think it will be something related to dynamic memory freeing, but I am not used to CORBA yet, so I'm not sure if I am using the data types in a proper way.


回答1:


Since it was impossible for me to find out what was wrong with my code, and generating the segmentation fault I have spoken about; I thought of an alternative way in which I could solve my problem: I have rebuilt the IDL interface so that the function has an 'out' parameter which allows me to return a sequence without any kind of problem.



来源:https://stackoverflow.com/questions/22919759/segmentation-fault-corba-c

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