C Client seg fault on batch call


I am finding if I so non-batch calls using the C Client things are fine. I can do 1000 retrievals, no problem.

However if I make a batch call, with a callback that just returns true, there is an issue. The program seg-faults if I try to do 50 loops of batch retrievals, versus say 5. This occurs when I put in a sleep of 1 second between loop iterations as well.

   for (int i = 0; i < 5; i++) {
    as_batch batch;
    as_batch_inita(&batch, 3);

    as_key_init(as_batch_keyat(&batch, 0), "ns", "r", "keyA");
    as_key_init(as_batch_keyat(&batch, 1), "ns", "r", "keyB");
    as_key_init(as_batch_keyat(&batch, 2), "ns", "r", "keyC");

    aerospike_batch_get(as, &err, NULL, &batch, batch_read_cb, NULL);

    as_key_destroy(as_batch_keyat(&batch, 0));
    as_key_destroy(as_batch_keyat(&batch, 1));
    as_key_destroy(as_batch_keyat(&batch, 2));

bool batch_read_cb(const as_batch_read* results, uint32_t n, void* udata)
return true;


as_batch_inita() initializes batch variables on the stack and your string keys are literals. Therefore, as_batch_destroy() should not be called. as_key_destroy() should never be called directly because as_batch_destroy() destroys the keys (when needed) as well.


Hi Brian, I switched out as_batch_inita with as_batch_init, and it looks like as_batch_destroy is running great at hundreds of iterations. I removed the as_key_destroy based on what you described.

Thank you!