Skip to content

Memory issues with reconnect #25

@wimrijnders

Description

@wimrijnders

I ran valgrind on my application and several issues popped up involving Beanstalk::Client::reconnect(). I will put the report in a separate post in this issue.

I'm not entirely sure how to fix this, but I did notice the following when looking at the code.

When looking at the code, I notice that strings are passed by value. eg:

Client::Client(string host, int port, float secs) {
...
void Client::connect(string _host, int _port, float secs) {

In addition, in reconnect(), connect is called with the member values of host, port and float secs already stored in the instance, which values are then again used to set the exact members passed.

void Client::connect(string _host, int _port, float secs) {
...
    host         = _host;
    port         = _port;
    timeout_secs = secs;
...
}
...
 void Client::reconnect() {
    disconnect();
    connect(host, port, timeout_secs);
}

This looks like a roundabout way of reconnecting and might be improved by using const string referemces. Since these methods are exactly where the memory issues occur as reported by valgrind, cleaning up might go some way to solve them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions