qof_backend_init

Neil Williams linux at codehelp.co.uk
Mon Jan 3 07:14:31 EST 2005


Lines 129+130 in qofbackend.c  are confusing me:

129    if (be->error_msg) g_free (be->error_msg);
130    be->error_msg = NULL;

I'm getting a segmentation fault because error_msg exists but is out of 
bounds. Why would it exist before g_new had finished? Why is it checked? 
Wouldn't any uninitialised value be out of range?

How can I reset be->error_msg before calling 
be = g_new (QofBackend, 1);
?

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 5840)]
0x40324069 in free () from /lib/libc.so.6
(gdb) bt
#0  0x40324069 in free () from /lib/libc.so.6
#1  0x402345e4 in g_free () from /usr/lib/libglib-2.0.so.0
#2  0x4002f7f8 in qof_backend_init (be=0x2c646e65) at qofbackend.c:139
#3  0x4004b2ad in qsf_backend_new () at qsf-backend.c:125
#4  0x4003dc82 in qof_session_load_backend (session=0x804f530, 
access_method=0x804f7c0 "file") at qofsession.c:393
#5  0x4003de8c in qof_session_begin (session=0x804f530,
    book_id=0x804f788 "file://opt/garfield/qof/share/qsf/qof-qsf.xml", 
ignore_lock=1, create_if_nonexistent=744779357)
    at qofsession.c:483
(gdb) up 3
#3  0x4004b2ad in qsf_backend_new () at qsf-backend.c:125
125             qsf_be = g_new(QSFBackend, 1);

(gdb) print qsf_be->be
$4 = {session_begin = 0, session_end = 0, destroy_backend = 0, load = 0, begin 
= 0, commit = 0, rollback = 0,
  compile_query = 0, free_query = 0, run_query = 0, sync = 0, counter = 
0x666f7162, events_pending = 0,
  process_events = 0, percentage = 0x6977645f, save_may_clobber_data = 
0x206f732e, last_err = ERR_BACKEND_NO_ERR,
  error_msg = 0x2c646e65 <Address 0x2c646e65 out of bounds>, fullpath = 
0x62696c20 ""}

qsf-backend.c
119 QofBackend*
120 qsf_backend_new(void)
121 {
122  QSFBackend *qsf_be;
123  QofBackend *be;
124 
125  qsf_be = g_new(QSFBackend, 1);

QSFBackend is:
struct QSFBackend_s 
{
 QofBackend be;
 qsf_param *params;
 char *fullpath;
};

Is this just a problem of working on a backend in QOF instead of GnuCash?

Why is gdb reporting it at line 139?

130    be->error_msg = NULL;
131    be->percentage = NULL;
132
133 #ifdef GNUCASH_MAJOR_VERSION
134    /* XXX remove these */
135    be->fullpath = NULL;
136    be->price_lookup = NULL;
137    be->export = NULL;
138 #endif
139 }

(removing those lines makes no odds.)

Commenting out:
129    if (be->error_msg) g_free (be->error_msg);

Fixes the seg fault completely - is it needed for any of the other backends?
Any problem with removing it in my next patch?

-- 

Neil Williams
=============
http://www.dclug.org.uk/
http://www.nosoftwarepatents.com/
http://sourceforge.net/projects/isbnsearch/
http://www.williamsleesmill.me.uk/
http://www.biglumber.com/x/web?qs=0x8801094A28BCB3E3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20050103/5508f40b/attachment.bin


More information about the gnucash-devel mailing list