I'm experiencing issues after sorting a std::vector of Elevator, a custom class.
Class definition:
class Elevator
{
private:
        uint16_t m_id;
        char *m_channel;
        ElevatorType m_type;
public:
        Elevator(uint16_t id, const char *channel, ElevatorType type);
        Elevator(const Elevator &other);
        ~Elevator();
        char *ToCString();
        bool operator<(const Elevator& rhs) const;
        static vector<Elevator> *ElevatorsFromWorkbook(const char *path);
};
The less operator is implemented like this:
bool Elevator::operator<(const Elevator& rhs) const
{
    return (this->m_id < rhs.m_id);
}
ToCString method is implemented like this:
char *Elevator::ToCString()
{
    char *output = (char*)malloc(sizeof(char) * (8+strlen(m_channel)));
    char type = 'U';
    if (m_type == ELEVATOR_TYPE_A)
    {
        type = 'A';
    }
    else if (m_type == ELEVATOR_TYPE_G)
    {
        type = 'G';
    } 
    else if (m_type == ELEVATOR_TYPE_M)
    {
        type = 'M';
    }
    sprintf(output,"%d %s %c",m_id,m_channel,type);
    return output;
}
Copy constructor:
Elevator::Elevator(const Elevator &other)
{
    m_id = other.m_id;
    m_channel = (char*)malloc(sizeof(char)*(strlen(other.m_channel)+1));
    strcpy(m_channel,other.m_channel);
    m_type = other.m_type;
}
Example of the issue:
std::vector<Elevator> elevators;
elevators.push_back(Elevator(4569,"CHANNEL3",ELEVATOR_TYPE_G));
elevators.push_back(Elevator(4567,"CHANNEL3",ELEVATOR_TYPE_G));
printf("%s\n",elevators.at(0).ToCString()); //Prints "4567 CHANNEL1 G"
std::sort(elevators.begin(),elevators.end());
printf("%s\n",elevators.at(0).ToCString()); //ISSUE: Prints "4567 4567 ▒#a G"
What am I doing wrong? Thanks for your time!
Note on compiling: I'm using Cygwin with these flags: -Wall -Wextra -fno-exceptions -fno-rtti -march=pentium4 -O2 -fomit-frame-pointer -pipe
 
     
    