sqlcxt/malloc error

Bit of a long one this

I am running the code below and I am getting a bus error when trying to make a struct member equal a variable. I stepped through the program in dbx and got the following. The structs of interest is raw_txns and la_ins_bkhead

Entered while loop in process()
t@1 (l@1) stopped in process at line 748 in file "normalise_raw_data.c"
748 sqlstm.sqpadto = sqlstm.sqadto;
(dbx) print raw_txns
raw_txns = {
h_store_id = 0x1003e47a0
h_txn_time = 0x1003e95d0
h_trans_date = 0x1003ed080
h_till_bank_indicator = 0x1003f6310
h_location_id = 0x1003fb140
h_cashier_id = 0xffffffff7d406cd8
h_trans_void = 0xffffffff7ce00b98
h_no_sale = 0xffffffff7ce00030
i_item_code = 0xffffffff7ce00db0
i_cancel_item = (nil)
i_subtract_item = 0xffffffff7ce00b98
i_unknwn_item = 0xffffffff7d600a68
i_complntry_item = (nil)
i_linked_item_ind = (nil)
i_department_mode = 0xf00000000
i_extend_price = (nil)
i_quantity = 0xffffffff7fffff97
i_unit_price = 0x500000002
i_at_for_qty = 0xffffffff7f724908
i_price_from_plu = 0x11c3a0
i_keyed_price = 0x2000
i_system_reduction = 0xffffffff7f7249d8
i_reduction_indicator = (nil)
i_refund_flag = (nil)
i_refund_reason_code = (nil)
i_item_entry_indicator = 0x18
dept = (nil)
class = (nil)
sku = (nil)
joint_venture_ind = (nil)
catchweight_ind = (nil)
}
(dbx) print la_ins_bkhead
la_ins_bkhead = {
txn_key = 0x100343c10
h_store_id = 0x100348a40
h_txn_time = 0x10034d870
h_trans_date = 0x100351320
h_till_bank_indicator = 0x10035a5b0
h_location_id = 0x10035f3e0
pos_txn_no = 0x100364210
h_cashier_id = 0x100369040
h_trans_void = 0x10036de70
h_no_sale = 0x10036f210
}
(dbx) step
t@1 (l@1) stopped in process at line 750 in file "normalise_raw_data.c"
750 sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
(dbx) print raw_txns
raw_txns = {
h_store_id = 0x1003e47a0
h_txn_time = 0x1003e95d0
h_trans_date = 0x1003ed080
h_till_bank_indicator = 0x1003f6310
h_location_id = 0x1
h_cashier_id = 0x1
h_trans_void = 0x1
h_no_sale = 0x1
i_item_code = 0x1
i_cancel_item = 0x1
i_subtract_item = 0x1
i_unknwn_item = 0x1
i_complntry_item = 0x1
i_linked_item_ind = 0x1
i_department_mode = 0x1
i_extend_price = 0x1
i_quantity = 0x1
i_unit_price = 0x1
i_at_for_qty = 0x1
i_price_from_plu = 0x1
i_keyed_price = 0x1
i_system_reduction = 0x1
i_reduction_indicator = 0x1
i_refund_flag = 0x1
i_refund_reason_code = 0x1
i_item_entry_indicator = 0x1
dept = 0x1
class = 0x1
sku = 0x1
joint_venture_ind = 0x1
catchweight_ind = 0x1
}
(dbx) print la_ins_bkhead
la_ins_bkhead = {
txn_key = 0x1
h_store_id = 0x1
h_txn_time = 0x1
h_trans_date = 0x1
h_till_bank_indicator = 0x1
h_location_id = 0x1
pos_txn_no = 0x1
h_cashier_id = 0x1
h_trans_void = 0x1
h_no_sale = 0x1
}

Does anyone know why the memory address for the most part are invalid after the sqlcxt statement. The raw_txns is a wierd one as only part of the struct is errored as the first four members are fine.

The sql the fetch pulls back is fine as I have checked this by running the sql myself.

Code is attached. Note the CALLOC functions are just wrappers for malloc. Any help is much appreciated.

Your code is not attached.

Are you using indicator variables for the fetch?
ie.,

EXEC SQL 
  FETCH mycursor into 
      :raw_tns :indicatorstruct;

I used,

EXEC SQL
FOR :PL_COMMIT_MAX_CTR
FETCH c_fetch_raw_txn INTO
:raw_txns.h_store_id,
etc

I attached the code. Or at least I think I did.