malloc_g + nic_parse_subopts

Hi everyone

I tried linking my network driver with malloc_g, and to my suprise the
first thing when I load my driver is that a error is generated in
nic_parse_subopts().

My code basically looks like this:
#define BCM4400_OFFSET(a) offsetof(bcm4400_options_t,a)
static drvr_subopt_tbl_t bcm4400OptionsTable[] =
{
{“flowcontrol”,BCM4400_OFFSET(flowcontrol),DRVR_OPT_FLAG_VAL_UINT32,0},
};

typedef struct {
nic_options_t nic;

//bcm4400 specific options
uint32_t flowcontrol;
} bcm4400_options_t;

typedef struct bleh {
//

bcm4400_options_t options;
/
} * PUM_DEVICE_BLOCK;

int bcm4400_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion,
char *options)
{
PUM_DEVICE_BLOCK handle;
struct itimerspec tvalue;
struct sigevent event;
uint16_t lan;
pthread_attr_t pattr;
struct sched_param param;
Nic_t *nic;
int ret;
drvr_subopt_tbl_chain_t link;

if(pci_attach(0) == -1 ) {
DbgPrint(“Can’t attach to the pci server! %d”,errno);
return errno;
}

/* let’s alloc a nic structure and put our PUM_DEVICE_BLOCK inside it */
nic = nic_create_dev(sizeof(UM_DEVICE_BLOCK));
handle=nic->ext;
memset(handle,0x0,sizeof(UM_DEVICE_BLOCK));
handle->nic = nic; //so we can access the nic struct from the callbacks
from the platform independant code.

//setup a few defaults
handle->options.nic.promiscuous = -1;
handle->options.nic.nomulticast = -1;
link.next = NULL;
link.table = bcm4400OptionsTable;
link.table_size = sizeof(bcm4400OptionsTable) / sizeof(drvr_subopt_tbl_t);
if((ret =
nic_parse_subopts(&handle->options,“devn-bcm4400”,options,&link)) != EOK) {
DbgPrint(“Failure parsing commandline options”);
errno=ret;
goto err1;
}


gdb say this:
/src/lib/c/alloc/dlist.c:637 - fatal alloc error - free malloc object
that is not a
llocated

Program received signal SIGSEGV, Segmentation fault.
0xb82139e4 in _malloc_error () from /x86/usr/lib/libmalloc.so.2
(gdb) bt
#0 0xb82139e4 in _malloc_error () from /x86/usr/lib/libmalloc.so.2
#1 0xb8210f7e in _list_release () from /x86/usr/lib/libmalloc.so.2
#2 0xb8211af8 in _free () from /x86/usr/lib/libmalloc.so.2
#3 0xb82114d2 in _free_direct () from /x86/usr/lib/libmalloc.so.2
#4 0xb821148d in __free () from /x86/usr/lib/libmalloc.so.2
#5 0xb82114fb in free () from /x86/usr/lib/libmalloc.so.2
#6 0xb8208da6 in nic_parse_subopts ()
from
/home/phearbear/DEV/ddk/ddk-6.2.1/network/src/hardware/devn/bcm4400/x86/dll
…g/bcm4400_g.so
#7 0xb8206fbe in bcm4400_init (dll_hdl=0x805c2c0, dpp=0x805b318,
ion=0x8057840,
options=0x8047ca1 “verbose=5”)


Am I able to use the malloc_g lib on a shared library like this/Am I
using the helper function in a errornous way/is there acctually a
memoryproblem inside that function?

If I don’t specify any arguments to my plugin, the problem isn’t there.
(also, the plugin seemingly work fine even with arguments running
without malloc_g)

I’m running QNX 6.2.1B PE.


Thanks in Advance

/Johan Björk