tanx for the advice...but how to avoid heap corruption? and why does it happen? anyway, finally here is the backtrace:
*** glibc detected *** malloc(): memory corruption: 0x0808e078 *** Program received signal SIGABRT, Aborted. [Switching to Thread -1213548864 (LWP 4348)] 0xffffe410 in __kernel_vsyscall () (gdb) ba #0 0xffffe410 in __kernel_vsyscall () #1 0x4fad57d5 in raise () from /lib/tls/libc.so.6 #2 0x4fad7149 in abort () from /lib/tls/libc.so.6 #3 0x4fb0927a in __libc_message () from /lib/tls/libc.so.6 #4 0x4fb1049c in _int_malloc () from /lib/tls/libc.so.6 #5 0x4fb11f01 in malloc () from /lib/tls/libc.so.6 #6 0xb7d95c03 in sqlite3Malloc (n=-16) at ./src/util.c:296 #7 0xb7d885f2 in sqlite3ParserAlloc ( mallocProc=0xb7d95bdc <sqlite3Malloc>) at parse.c:1302 #8 0xb7d9382d in sqlite3RunParser (pParse=0xbffff550, zSql=0x8093c38 "SELECT subjNum FROM \"images\" WHERE id==15;", pzErrMsg=0xbffff54c) at ./src/tokenize.c:349 #9 0xb7d8c777 in sqlite3_prepare (db=0x808d5d0, zSql=0x8093c38 "SELECT subjNum FROM \"images\" WHERE id==15;", nBytes=-1, ppStmt=0xbffff648, pzTail=0x0) at ./src/prepare.c:440 #10 0x0804d0ef in subjId (db=0x808d5d0, id=15, subj=0xbffff748, test=0x0) at database.c:901 #11 0x0804e8f8 in featVect (db=0x808d5d0, recog_id=1, maxEigen=0) at database.c:1662 #12 0x0804a26a in main (argc=5, argv=0xbffff864) at main.c:400 (gdb) I also noticed that error occours even if the requested row id is every time the same! So the problem occours after a certain number of iterations. The code to read is something like this: sqlite3_stmt *pStmt=0; char *sql=0; int sql_error=0; asprintf(&sql, "SELECT subjNum FROM \"images\" WHERE id==%d;" id); if ( !sqlite3_prepare(db, sql, -1, &pStmt, 0) ) { if (sqlite3_step(pStmt)==SQLITE_ROW) { test = (char*) sqlite3_column_text (pStmt,0); } else { fprintf(stderr,"\nWARNING: No image associated to requested id\n"); sql_error = 1; } } else { fprintf(stderr, "\nERROR: SQL prepare error:\n\t%s\n", sqlite3_errmsg(db)); sql_error=1; } if ( sqlite3_finalize(pStmt) != SQLITE_OK ) { fprintf(stderr, "\nERROR: SQL finalization error:\n\t%s\n", sqlite3_errmsg(db)); sql_error=1; } free(sql); if (sql_error) { sqlite3_close (db); exit(1); } it is inside a function that is called iteratively from another function, incrementing the passed id num tanks __________________________________________________________________ TISCALI ADSL Solo con Tiscali Adsl navighi senza limiti e telefoni senza canone Telecom a partire da 19,95 Euro/mese. Attivala subito, I PRIMI DUE MESI SONO GRATIS! CLICCA QUI: http://abbonati.tiscali.it/adsl/sa/1e25flat_tc/