CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Imebra, C++ in QT project gives malloc: error for object

    I'm trying to convert dicom .dcm file to .jpeg using Imebra in C++ app using QT Creator as dev environment.

    I've downloaded Imebra and was able to run QT project example for Dicom2Jpeg conversion successfully. But when I tried to copy same code to my C++ app it failed to run with following error msg:

    malloc: * error for object xxxxxx: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

    I have followed steps on adding Imebra files to my project as it was shown on Imebra site. Also used their qt project as example. My main.cpp open dicom file, then loads it to dataset, then calls my dialog window. It crashes on loading dataset.

    #include "QApplication.h"
    #include "QHBoxLayout.h"
    #include "mydialog.h"
    #include "iostream.h"

    include "library/imebra/include/imebra.h"
    int main( int argc, char ** argv ){

    using namespace puntoexe;
    ptr<stream> readStream(new stream);
    readStream->openFile("/pathToDcmFile/test.dcm",std::ios_base::in);

    ptr<streamReader> reader(new streamReader(readStream));

    //this line causes malloc error
    ptr<imebra:ataSet> dSet=imebra::codecs::codecFactory::getCodecFactory()->load(reader,2048);

    Q_INIT_RESOURCE(images);

    QApplication a( argc, argv );

    MyDialog md;
    md.show();

    return a.exec();
    }

    Deeper debugging showed that source of error is in JpegCodec.cpp file readStream() function when checking JpegSignature to see if it's in wrong format with resulting internal PUNTOEXE error "detected a wrong format".

    Interesting thing is that while running same test dcm file using given dicom2jpeg example (which has exact same code of opening file and loading it) gives no errors and converts to jpeg successfully. So I know it's not the file issue, but the way imebra code is integrated into my C++ app.

    My dev environment: macbook pro with Lion OS, QT Creator, QT project, C++ code, ITK library added, Imebra files are completely integrated as part of the Qt project.

    So, my question is how do I work/link/reference/call Imebra functionality in QT project? Am I forgetting to link something, or some object is not instantiated/deleted on time?

    Any ideas are highly appreciated,

    Evushka

  2. #2
    Join Date
    Oct 2012
    Posts
    4

    Re: Imebra, C++ in QT project gives malloc: error for object

    It was suggested on another forum that problem was caused by codec factory calling jpeg codec instead of dicom codec.

    Solution: I have changed codec factory to dicm factory and it fixed the problem. My new code is given below.

    imebra::codecs:icomCodec* pTmp = new imebra::codecs:icomCodec();

    ptr<stream> readStream(new stream);
    readStream->openFile(argv[0],std::ios_base::in);

    ptr<streamReader> reader(new streamReader(readStream));

    ptr<imebra:ataSet> tdataSet;
    tdataSet=pTmp->read(reader,2048);

    delete pTmp;

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Imebra, C++ in QT project gives malloc: error for object

    Quote Originally Posted by Evushka View Post
    It was suggested on another forum that problem was caused by codec factory calling jpeg codec instead of dicom codec.

    Solution: I have changed codec factory to dicm factory and it fixed the problem. My new code is given below.
    Well, all I can say is that the code sure looks like it would leak memory if those calls to "new" fail or if an exception is thrown anywhere in that code. For example:
    Code:
    imebra::codecs::dicomCodec* pTmp = new imebra::codecs::dicomCodec();
    Why does this need to be dynamically allocated? Why not just do this:
    Code:
    imebra::codecs::dicomCodec pTmp(imebra::codecs::dicomCodec());
    Then there is no need for the "delete" at the end.

    Regards,

    Paul McKenzie

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured