Hi all,
I have an issue with a segfault I can't localize. I run MHD
from a binary package for DEBIAN11 and start the server with
the following code (similar to the post example) to serve a
GET request:
int
main (int argc, char **argv)
{
time_t now;
struct timeval tv;
struct timeval *tvp;
fd_set rs;
fd_set ws;
fd_set es;
MHD_socket max;
MHD_UNSIGNED_LONG_LONG mhd_timeout;
mylast_alive = (unsigned int)time(&now);
if (!(hka = hkaconn ()))
{
fprintf (stderr, "%s\n", mysql_error(&hkahdl));
exit (1);
}
srand ((unsigned int)time(&now));
vbad =
MHD_start_daemon ( MHD_USE_ERROR_LOG,
1431,
&on_client_connect, myclient_ip,
&create_response, NULL,
MHD_OPTION_NOTIFY_COMPLETED,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)120,
MHD_OPTION_CONNECTION_LIMIT, (unsigned int)500,
MHD_OPTION_END
);
if (NULL == vbad)
return (emsg ("Can't create daemon"));
while (1)
{
expire_sessions ();
printf ("Nach EXP_SESS\n");
max = 0;
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
if (MHD_YES != MHD_get_fdset (vbad, &rs, &ws, &es, &max))
break; /* fatal internal error */
if (MHD_get_timeout (vbad, &mhd_timeout) == MHD_YES)
{
tv.tv_sec = mhd_timeout / 1000;
tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
tvp = &tv;
}
else
tvp = NULL;
if (-1 == select (max + 1, &rs, &ws, &es, tvp))
{
if (EINTR != errno)
abort ();
}
printf ("Nach SELECT\n");
MHD_run (vbad);
printf ("Nach RUN\n");
}
MHD_stop_daemon (vbad);
return 0;
}/*end main*/
The request is properly served and the webpage appears on the
browser as it should. create_response() ends like this:
{
....
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
printf ("Nach destroy\n");
return MHD_YES;
}
Immediately after the printout, I get a segfault. Using gdb yields
Reading symbols from ./vbad...
(gdb) run
Starting program: /home/klemens/progc/vba/vbad
[Thread debugging using libthread_db enabled]
Using host libthread_db library
"/lib/x86_64-linux-gnu/libthread_db.so.1".
Nach EXP_SESS
Nach SELECT
Nach RUN
Nach EXP_SESS
Nach SELECT
CR1
CR2
CR3
URL>>/nz7eR48JKpV/GU0t36aWnw==<<
NEWSN>>5CA207CF66C5FC7378B31FD151F8ECC9|1<<
Nach GETPAGE
Nach destroy
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000003 in ?? ()
and I have no idea what causes the segfault and where this
happens. Any help is higly appreciated.
kginbg.