Segmentation fault in sqlcxt()
I am using the below function in my C code for connecting to the oracle database. The below function is causing segmentation fault sometime while work at the other time
static int Connect(char *string)
{
EXEC SQL BEGIN DECLARE SECTION;
static char login[80];
EXEC SQL END DECLARE SECTION;
strcpy((char *)login, string);
EXEC SQL CONNECT :login ;
if (sqlca.sqlc开发者_运维知识库ode < 0)
return(-1);
return(0);
}
Below is the debugger report generated with the core file. Any suggestions on this.
program terminated by signal SEGV (no mapping at the fault address)
0xffffffffffffffff: <bad address 0xffffffffffffffff>
Current function is Connect
375 sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
[20] 0xffffffff7e587078(0x0, 0x100210f80, 0xffffffff7fffc850, 0x1000e4dd0, 0xff000000000000, 0x8080808080808080), at 0xffffffff7e587078
=>[21] login(orastring = 0xffffffff7fffcef8 "user123/abcd@sunn.adams"), line 375 in "connect.c"
From the debugger report, seg fault is because of accessing inaccessible memory.
I would suggest two places to put some checks.
(a) Check input parameter 'string'
for NULL
values before using it.
(b) Use strncpy()
instead of strcpy()
Have had many similar issues (using Oracle 8.1.7) and most of what I've found on the 'net simply says: Oracle Bug (especially if sqlcxt eventually calls lxchcsn
I had a program running 25 threads which seemed to work. I changes some settings that meant an increase in the frequency of DB calls and this issue started to occur. When I put mutexes around the DB calls, the issue went away (which is bizarre because I could see 25 individual DB connections - each thread had its own context) - and putting in the mutexes sort of defeats the purpose of multi-threading.
Basically, I think it's an Oracle issue
精彩评论