shafreeck / cetcd

Cetcd is a C client library for etcd with full features support
Apache License 2.0
69 stars 39 forks source link

Segmentation fault execute cetcd_get example when the server down; #31

Closed dennisip86 closed 8 years ago

dennisip86 commented 8 years ago

Here is the testing code:

#include <stdio.h>
#include <stdlib.h>

#include "cetcd.h"

int main()
{
    cetcd_client cli;
    cetcd_response *resp;
    cetcd_array addrs;

    cetcd_array_init(&addrs, 3);
    cetcd_array_append(&addrs, (void *)"http://192.168.4.247:2379");
    cetcd_array_append(&addrs, (void *)"http://192.168.4.247:2381");
    cetcd_array_append(&addrs, (void *)"http://192.168.4.247:2383");

    cetcd_client_init(&cli, &addrs);

    resp = cetcd_get(&cli, "/test/test.conf");
    if(resp->err) {
        printf("error :%d, %s (%s)\n", resp->err->ecode, resp->err->message, resp->err->cause);
    }
    cetcd_response_print(resp);
    cetcd_response_release(resp);

    cetcd_array_destroy(&addrs);
    cetcd_client_destroy(&cli);

    return 0;
}

A segmentation fault happens when one or all of the etcd cluster server down.

shafreeck commented 8 years ago

@dennisip86 Thanks very much for your report. It is because parser.json was not initialized. The latest master branch fixed this problem. Please checkout and see if it works for you.