trafficserver-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Owens, Steve" <Steve.Ow...@disney.com>
Subject Question on TSMalloc
Date Thu, 24 Jan 2013 22:32:40 GMT

I ran into a bit of an issue today related to TSMalloc

Suppose I have a plugin which defines a plugin data structure such as:


typedef struct {

        int state;

        TSVIO output_vio;

        TSIOBuffer output_buffer;

        TSIOBufferReader output_reader;

        std::string foo;

    } TransformationData;



And I have some plugin code which does this:


void allocTransformationData(){

TransformationData *pData;


pData = (TransformationData *) TSmalloc(sizeof(TransformationData));

pData->state = STATE_START;

pData->output_buffer = NULL;

pData->output_vio = NULL;

pData->output_reader = NULL;

pData->foo.assign("bar");


return pData;

}


The line  pData->foo.assign("bar");


Will result in a segmentation fault.


Is there a best practice idiom for using std::string items in custom continuation data?  For
example should I be using


typedef struct {

        int state;

        TSVIO output_vio;

        TSIOBuffer output_buffer;

        TSIOBufferReader output_reader;

        std::string *foo;

    } TransformationData;


And


Void allocTransformationData(){

TransformationData *pData;


pData = (TransformationData *) TSmalloc(sizeof(TransformationData));

pData->state = STATE_START;

pData->output_buffer = NULL;

pData->output_vio = NULL;

pData->output_reader = NULL;



pData->foo = new std::string;

        pData->foo.assign("bar");


return pData;

}


Or should I use:


Void allocTransformationData(){

TransformationData *pData;


pData = (TransformationData *) TSmalloc(sizeof(TransformationData));

pData->state = STATE_START;

pData->output_buffer = NULL;

pData->output_vio = NULL;

pData->output_reader = NULL;



pData->foo = (std::string*) Tsmalloc(sizeof(std::string));

        pData->foo.assign("bar");


return pData;

}




Mime
View raw message