shiyilei / protobuf-c

Automatically exported from code.google.com/p/protobuf-c
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Memory leak in failed_waiting.timer #70

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create new RPC client
2. Do not run server!
3. Destroy client

What is the expected output? What do you see instead?

If autoreconnect is enabled, client_failed() allocates 
client->info.failed_waiting.timer. If client is then destroyed, timer is never 
freed: client state is PROTOBUF_C_CLIENT_STATE_FAILED_WAITING, 
destroy_client_rpc() removes timer from the timer tree but doesn't free it.

What version of the product are you using? On what operating system?
protobuf-c-0.14, Ubuntu natty

Please provide any additional information below.

Simple program:

static void* my_alloc(void *allocator_data, size_t size)
{
    void *pointer = malloc(size);
    printf("ALLOC: pointer=%p, allocator_data=%p, size=%zd\n", pointer, allocator_data, size);
    return pointer;
}

static void my_free(void *allocator_data, void *pointer)
{
    printf("FREE:  pointer=%p, allocator_data=%p\n", pointer, allocator_data);
    free(pointer);
}

int main(int __attribute__ ((unused)) argc, char __attribute__ ((unused))* 
argv[])
{
    ProtobufCService *rpc_service;

    protobuf_c_default_allocator.alloc      = my_alloc;
    protobuf_c_default_allocator.free       = my_free;
    protobuf_c_default_allocator.max_alloca = 0;

    rpc_service = protobuf_c_rpc_client_new(PROTOBUF_C_RPC_ADDRESS_LOCAL, "/tmp/protobuf", NULL, NULL);

    protobuf_c_dispatch_run(protobuf_c_dispatch_default()); 

    rpc_service->destroy(rpc_service);

    protobuf_c_dispatch_destroy_default();

    return 0;
}

Output:

ALLOC: pointer=0x15d1010, allocator_data=(nil), size=160
ALLOC: pointer=0x15d10c0, allocator_data=(nil), size=64
ALLOC: pointer=0x15d1110, allocator_data=(nil), size=128
ALLOC: pointer=0x15d11a0, allocator_data=(nil), size=64
ALLOC: pointer=0x15d11f0, allocator_data=(nil), size=192
ALLOC: pointer=0x15d12c0, allocator_data=0x652540, size=184
ALLOC: pointer=0x15d1380, allocator_data=0x652540, size=14
ALLOC: pointer=0x15d13a0, allocator_data=(nil), size=40
ALLOC: pointer=0x15d13d0, allocator_data=0x652540, size=59
ALLOC: pointer=0x15d1420, allocator_data=0x652540, size=72
FREE:  pointer=0x15d13d0, allocator_data=0x652540
FREE:  pointer=0x15d1380, allocator_data=0x652540
FREE:  pointer=0x15d12c0, allocator_data=0x652540
FREE:  pointer=0x15d13a0, allocator_data=(nil)
FREE:  pointer=0x15d10c0, allocator_data=(nil)
FREE:  pointer=0x15d11a0, allocator_data=(nil)
FREE:  pointer=0x15d1110, allocator_data=(nil)
FREE:  pointer=0x15d11f0, allocator_data=(nil)
FREE:  pointer=0x15d1010, allocator_data=(nil)

Pointer 0x15d1420 (size = 72 = sizeof(ProtobufCDispatchTimer)) was not freed.

Original issue reported on code.google.com by l...@zadarastorage.com on 11 Sep 2011 at 4:45

GoogleCodeExporter commented 8 years ago
I also have this problem - just freeing seems to work for me

Original comment by florian....@gmail.com on 14 May 2012 at 1:12

Attachments: