# Program terminated with signal 11, Segmentation fault

**URL:** <https://discuss.aerospike.com/t/program-terminated-with-signal-11-segmentation-fault/329>\
**Category:** C Client Library\
**Created:** [August 25, 2014, 9:30pm UTC](https://discuss.aerospike.com/t/program-terminated-with-signal-11-segmentation-fault/329 "2014-08-25T21:30:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldforum](https://avatars.discourse-cdn.com/v4/letter/o/13edae/32.png) [@oldforum](https://discuss.aerospike.com/u/oldforum)\
**Post date:** [August 25, 2014, 9:30pm UTC](https://discuss.aerospike.com/t/program-terminated-with-signal-11-segmentation-fault/329/1 "2014-08-25T21:30:54Z")

</div>

Postby romalin99 » Wed Aug 20, 2014 5:18 am

> 0 0x000000000041e267 in cl\_compile (info1=0, info2=1, info3=0, ns=, set=, key=0x0, digest=0x7fff6fafd1d1, values=0x7fff6ef0b340, operator=CL\_OP\_WRITE, operations=0x0, n\_values=3, buf\_r=0x7fff6ef0b250, buf\_sz\_r=0x7fff6ef0b248, cl\_w\_p=0x7fff6ef0b410, d\_ret=0x7fff6ef0b210, trid=0, scan\_param\_field=0x0, call=0x0, udf\_type=0 ‘\000’) at src/main/citrusleaf/citrusleaf.c:870 870 src/main/citrusleaf/citrusleaf.c: No such file or directory. in src/main/citrusleaf/citrusleaf.c Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6\_5.3.x86\_64 keyutils-libs-1.4-4.el6.x86\_64 krb5-libs-1.10.3-15.el6\_5.1.x86\_64 libcom\_err-1.41.12-18.el6\_5.1.x86\_64 libselinux-2.0.94-5.3.el6\_4.1.x86\_64 lua-5.1.4-4.1.el6.x86\_64 openssl-1.0.1e-16.el6\_5.15.x86\_64 zlib-1.2.3-29.el6.x86\_64 (gdb) bt

> 0 0x000000000041e267 in cl\_compile (info1=0, info2=1, info3=0, ns=, set=, key=0x0, digest=0x7fff6fafd1d1, values=0x7fff6ef0b340, operator=CL\_OP\_WRITE, operations=0x0, n\_values=3, buf\_r=0x7fff6ef0b250, buf\_sz\_r=0x7fff6ef0b248, cl\_w\_p=0x7fff6ef0b410, d\_ret=0x7fff6ef0b210, trid=0, scan\_param\_field=0x0, call=0x0, udf\_type=0 ‘\000’) at src/main/citrusleaf/citrusleaf.c:870 1 0x000000000041ecdf in do\_the\_full\_monte (asc=0x158d030, info1=0, info2=1, info3=, ns=0x7fff6fafd141 “test”, set=, key=0x0, digest=0x7fff6fafd1d1, values=0x7fff6ef0b308, operator=CL\_OP\_WRITE, operations=0x0, n\_values=0x7fff6ef0b304, cl\_gen=0x0, cl\_w\_p=0x7fff6ef0b410, trid=0x7fff6ef0b318, setname\_r=0x0, call=0x0, cl\_ttl=0x0) at src/main/citrusleaf/citrusleaf.c:1322 2 0x000000000041fdb5 in citrusleaf\_put\_digest\_with\_setname (asc=, ns=, set=, digest=, values=0x7fff6ef0b340, n\_values=3, cl\_w\_p=0x7fff6ef0b410) at src/main/citrusleaf/citrusleaf.c:1658 3 0x000000000040c31e in aerospike\_key\_put (as=0x7fff6fafd8f0, err=0x7fff6fafd4d0, policy=, key=0x7fff6fafd140, rec=0x7fff6fafd060) at src/main/aerospike/aerospike\_key.c:339 4 0x000000000040afee in main (argc=1, argv=0x7fff6fb00058) at test1.c:151

> codes: for(unsigned long i=0;i\<500000;i++) { char keybuf[100]={0}; snprintf(keybuf,sizeof(keybuf),“ro%010lu”,i); as\_key keytmp; as\_key\_init\_str(&keytmp,“test”,“demo-set2”,keybuf);

> as\_record rectmp; as\_record\_inita(&rectmp,3); as\_record\_set\_int64(&rectmp,“bin1”,i); as\_record\_set\_int64(&rectmp,“bin2”,i+10); as\_record\_set\_int64(&rectmp,“bin3”,i+20); //as\_record\_set\_str(&rectmp,“bin3”,data1);

> if( AEROSPIKE\_OK != aerospike\_key\_put(&as, &err,NULL,&keytmp,&rectmp) ) { fprintf(stderr,“err(%d) %s at [%s:%d]\n”, err.code, err.message, err.file, err.line); cleanup(&as); exit(-1); } } only 65271 keys putted, subsequently Segmentation fault (core dumped). please help me . and thanks.

---

<div class="post-metadata">

**Author:** ![oldforum](https://avatars.discourse-cdn.com/v4/letter/o/13edae/32.png) [@oldforum](https://discuss.aerospike.com/u/oldforum)\
**Post date:** [August 25, 2014, 9:31pm UTC](https://discuss.aerospike.com/t/program-terminated-with-signal-11-segmentation-fault/329/2 "2014-08-25T21:31:09Z")

</div>

by devops02 » Wed Aug 20, 2014 10:16 am

Hi,

I was wondering what version of Aerospike Community are you using? Also just to confirm are you using the C client?

Jerry

---

<div class="post-metadata">

**Author:** ![oldforum](https://avatars.discourse-cdn.com/v4/letter/o/13edae/32.png) [@oldforum](https://discuss.aerospike.com/u/oldforum)\
**Post date:** [August 25, 2014, 9:33pm UTC](https://discuss.aerospike.com/t/program-terminated-with-signal-11-segmentation-fault/329/3 "2014-08-25T21:33:16Z")

</div>

by romalin99 » Wed Aug 20, 2014 7:17 pm

Thanks to you answer for my the request firstly,

> machine os-platform : cetos6.5 the server package: aerospike-server-community-3.3.12-1.el6.x86\_64.rpm tools-packages: aerospike-tools-3.3.13-1.el6.x86\_64.rpm client packages: aerospike-client-c-3.0.72-1.el6.x86\_64.rpm aerospike-client-c-devel-3.0.72-1.el6.x86\_64.rpm
> 
> * * *
> 
> the whole codes as follows:

> include \<stdio.h\> include \<string.h\> include \<stdbool.h\> include \<stdlib.h\> include \<stdint.h\> include \<unistd.h\> include \<aerospike/aerospike.h\> include \<aerospike/aerospike\_index.h\> include \<aerospike/aerospike\_key.h\> include \<aerospike/aerospike\_udf.h\> include \<aerospike/as\_bin.h\> include \<aerospike/as\_bytes.h\> include \<aerospike/as\_error.h\> include \<aerospike/as\_config.h\> include \<aerospike/as\_key.h\> include \<aerospike/as\_operations.h\> include \<aerospike/as\_record.h\> include \<aerospike/as\_record\_iterator.h\> include \<aerospike/as\_status.h\> include \<aerospike/as\_val.h\>

> //#include \<\> //using namespace std; define LOG(\_fmt, \_args…) { printf(\_fmt “\n”, ## \_args); fflush(stdout); } static void cleanup(aerospike\* p\_as) { as\_error err; aerospike\_close(p\_as, &err); aerospike\_destroy(p\_as); } static void dump\_bin(const as\_bin\* p\_bin) { if (! p\_bin) { LOG(" null as\_bin object"); return; }

> char\* val\_as\_str = as\_val\_tostring(as\_bin\_get\_value(p\_bin));

> LOG(" %s : %s", as\_bin\_get\_name(p\_bin), val\_as\_str);

> free(val\_as\_str); } void dump\_record(const as\_record\* p\_rec) { if (! p\_rec) { LOG(" null as\_record object"); return; }

> if (p\_rec-\>key.valuep) { char\* key\_val\_as\_str = as\_val\_tostring(p\_rec-\>key.valuep); LOG(" key: %s", key\_val\_as\_str); free(key\_val\_as\_str); }

> uint16\_t num\_bins = as\_record\_numbins(p\_rec);

> LOG(" generation %u, ttl %u, %u bin%s", p\_rec-\>gen, p\_rec-\>ttl, num\_bins, num\_bins == 0 ? “s” : (num\_bins == 1 ? “:” : “s:”));

> as\_record\_iterator it; as\_record\_iterator\_init(&it, p\_rec);

> while (as\_record\_iterator\_has\_next(&it)) { dump\_bin(as\_record\_iterator\_next(&it)); }

> as\_record\_iterator\_destroy(&it); }

---

<div class="post-metadata">

**Author:** ![oldforum](https://avatars.discourse-cdn.com/v4/letter/o/13edae/32.png) [@oldforum](https://discuss.aerospike.com/u/oldforum)\
**Post date:** [August 25, 2014, 9:33pm UTC](https://discuss.aerospike.com/t/program-terminated-with-signal-11-segmentation-fault/329/4 "2014-08-25T21:33:45Z")

</div>

> bool read\_test\_record(aerospike\* p\_as,as\_key\* p\_key) { as\_error err; as\_record\* p\_rec = NULL;

> // Read the test record from the database. if (aerospike\_key\_get(p\_as, &err, NULL, p\_key, &p\_rec) != AEROSPIKE\_OK) { LOG(“aerospike\_key\_get() returned %d - %s”, err.code, err.message); return false; }

> // If we didn’t get an as\_record object back, something’s wrong. if (! p\_rec) { LOG(“aerospike\_key\_get() retrieved null as\_record object”); return false; }

> // Log the result. LOG(“record was successfully read from database:”); dump\_record(p\_rec);

> // Destroy the as\_record object. as\_record\_destroy(p\_rec);

> return true; } int main(int argc,char\* argv) { //step1 configuring the client as\_config config; as\_config\_init(&config); as\_config\_add\_host(&config,“127.0.0.1”,3000); //as\_config\_set\_user(&cfg,“”,“”)

> //step2 initilize a client aerospike as; aerospike\_init(&as,&config);

> //step3 establishing a connection as\_error err; if(aerospike\_connect(&as,&err) != AEROSPIKE\_OK) { fprintf(stderr,“err(%d) %s at [%s:%d]\n”,err.code, err.message, err.file, err.line); aerospike\_destroy(&as); exit(-1); }

> //dosomething as\_key key;//namespace ,set key //as\_key\_init(&key,“test”,“demo\_set”,“test\_key”); as\_key\_init\_str(&key,“test”,“demo-set”,“test-key”);

> as\_record rec; as\_record\_inita(&rec,2);//指定这条记录有几列 as\_record\_set\_int64(&rec,“test-bin-1”,1234);//第一列设为整型 as\_record\_set\_str(&rec,“test-bin-2”,“test-bin-2-data”);//The second bin is called “test-bin-2”, and is of type string

> if( AEROSPIKE\_OK != aerospike\_key\_put(&as, &err,NULL,&key,&rec) ) { fprintf(stderr,“err(%d) %s at [%s:%d]\n”, err.code, err.message, err.file, err.line); cleanup(&as); exit(-1); } char data1=“101087648756478androiapplu51-661538461533846151iPhone3G8248a74c6060ff89da9793e3d651dddc36a997f1.2.3.10Yaho876487564781407401201018489536cQ17f9Q4362Q9e0bQa9f2964bd9a067825159Q7611Q46hbQa987Q222e3164cbIAB203254.2.”; for(unsigned long i=0;i\<500000;i++) { char keybuf[100]={0}; snprintf(keybuf,sizeof(keybuf),“ro%010lu”,i); printf(“key={%s}\n”,keybuf); as\_key keytmp; as\_key\_init\_str(&keytmp,“test”,“demo-set2”,keybuf);

> as\_record rectmp; as\_record\_inita(&rectmp,3); as\_record\_set\_int64(&rectmp,“bin1”,i); as\_record\_set\_int64(&rectmp,“bin2”,i+10); as\_record\_set\_int64(&rectmp,“bin3”,i+20); //as\_record\_set\_str(&rectmp,“bin3”,data1);

> if( AEROSPIKE\_OK != aerospike\_key\_put(&as, &err,NULL,&keytmp,&rectmp) ) { fprintf(stderr,“err(%d) %s at [%s:%d]\n”, err.code, err.message, err.file, err.line); cleanup(&as); exit(-1); } } //get data as\_record\* p\_rec = NULL;

> // Read the test record from the database. if (aerospike\_key\_get(&as, &err, NULL, &key, &p\_rec) != AEROSPIKE\_OK) { LOG(“aerospike\_key\_get() returned %d - %s”, err.code, err.message); return false; }

> // If we didn’t get an as\_record object back, something’s wrong. if (! p\_rec) { LOG(“aerospike\_key\_get() retrieved null as\_record object”); return false; } // Log the result. LOG(“record was successfully read from database:”); dump\_record(p\_rec); // Destroy the as\_record object. as\_record\_destroy(p\_rec);

> // Generate another as\_record object to write. as\_record\_inita(&rec,2); as\_record\_set\_int64(&rec, “test-bin-2”, 2222); as\_record\_set\_str(&rec, “test-bin-3”, “test-bin-3-data”); //dump\_record(&rec); if (aerospike\_key\_put(&as, &err, NULL, &key, &rec) != AEROSPIKE\_OK) { LOG(“aerospike\_key\_put() returned %d - %s”, err.code, err.message); cleanup(&as); exit(-1); }

> LOG(“write2 succeeded”); read\_test\_record(&as,&key);

> /\* if (aerospike\_key\_remove(&as, &err, NULL, &key) != AEROSPIKE\_OK) { LOG(“aerospike\_key\_remove() returned %d - %s”, err.code, err.message); cleanup(&as); exit(-1); } \*/ //step4-0 clean up resourse as\_record\_destroy(&rec);//as\_record\_destroy() is not strictly needed.

> //step5 cleanup cleanup(&as); return 0; }

---

<div class="post-metadata">

**Author:** ![oldforum](https://avatars.discourse-cdn.com/v4/letter/o/13edae/32.png) [@oldforum](https://discuss.aerospike.com/u/oldforum)\
**Post date:** [August 25, 2014, 9:34pm UTC](https://discuss.aerospike.com/t/program-terminated-with-signal-11-segmentation-fault/329/5 "2014-08-25T21:34:14Z")

</div>

by wchu » Fri Aug 22, 2014 11:57 am

as\_record\_inita() internally uses alloca() to reserve record/bin space on stack. When this is done in a large loop, this can blow the available stack space of the calling function.

A simple solution is to move the as\_record\_inita() function outside of the loop:

> as\_record rectmp; as\_record\_inita(&rectmp,3);

> for (unsigned long i=0;i\<500000;i++) { char keybuf[100]={0}; snprintf(keybuf,sizeof(keybuf),“ro%010lu”,i); as\_key keytmp; as\_key\_init\_str(&keytmp,“test”,“demo-set2”,keybuf); as\_record\_set\_int64(&rectmp,“bin1”,i); as\_record\_set\_int64(&rectmp,“bin2”,i+10); as\_record\_set\_int64(&rectmp,“bin3”,i+20);

> if( AEROSPIKE\_OK != aerospike\_key\_put(&as, &err,NULL,&keytmp,&rectmp) ) { fprintf(stderr,“err(%d) %s at [%s:%d]\n”, err.code, err.message, err.file, err.line); exit(-1); } }

Similar caution should be applied to as\_query\_select\_inita(), as\_batch\_inita(), as\_operations\_inita() and as\_scan\_select\_inita()

---

<div class="post-metadata">

**Author:** ![oldforum](https://avatars.discourse-cdn.com/v4/letter/o/13edae/32.png) [@oldforum](https://discuss.aerospike.com/u/oldforum)\
**Post date:** [August 25, 2014, 9:34pm UTC](https://discuss.aerospike.com/t/program-terminated-with-signal-11-segmentation-fault/329/6 "2014-08-25T21:34:26Z")

</div>

by romalin99 » Sun Aug 24, 2014 7:24 pm

thanks to give my help about this problem.
