Possible memory allocation bug

View: New views
5 Messages — Rating Filter:   Alert me  

Possible memory allocation bug

by Jose Luis Blanco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I've not been able to get a consistent test code, but I'm having
program crashes (in Linux) and asserts (in Windows) when calling
"cvGoodFeaturesToTrack".
Switching from the current SVN code to the old 1.0.0 solves the issue.

Under Windows, the assert  I got is from cvMorph.cpp@260, so it seems
it has to do with misaligned memory. In further debugging, I got no
more clues...
In Linux, I've tried to debug my program with Valgrind to detect
memory corruption from either opencv or my code but it detects no
errors and the program just dies with the message "Killed"...

However, it can still be an issue of memory corruption within valid
memory addresses so Valgrind doesn't comply. Perhaps it's a problem of
my code, but since switching to opencv 1.0.0 solves it I wanted to let
you know.

Best,
JL

--

___________________________________________________________

Jose-Luis Blanco-Claraco      Phone: +34 952 132848
Dpto. Ingenieria de Sistemas y Automatica
E.T.S.I. Telecomunicacion       Fax: +34 952 133361
Universidad de Malaga
Campus Universitario de Teatinos
29071 Malaga, Spain

http://www.isa.uma.es/jlblanco
___________________________________________________________

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

Re: Possible memory allocation bug

by Vadim Pisarevsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Jose,

I can not reproduce it with the current SVN on Mac. At least, lkdemo runs fine.
There was such problem with misaligned buffers a couple of weeks ago, but it is solved in the trunk version now.

Regards,
Vadim

On Thu, Sep 3, 2009 at 2:10 PM, Jose Luis Blanco <joseluisblancoc@...> wrote:
Hello,

I've not been able to get a consistent test code, but I'm having
program crashes (in Linux) and asserts (in Windows) when calling
"cvGoodFeaturesToTrack".
Switching from the current SVN code to the old 1.0.0 solves the issue.

Under Windows, the assert  I got is from cvMorph.cpp@260, so it seems
it has to do with misaligned memory. In further debugging, I got no
more clues...
In Linux, I've tried to debug my program with Valgrind to detect
memory corruption from either opencv or my code but it detects no
errors and the program just dies with the message "Killed"...

However, it can still be an issue of memory corruption within valid
memory addresses so Valgrind doesn't comply. Perhaps it's a problem of
my code, but since switching to opencv 1.0.0 solves it I wanted to let
you know.

Best,
JL

--

___________________________________________________________

Jose-Luis Blanco-Claraco      Phone: +34 952 132848
Dpto. Ingenieria de Sistemas y Automatica
E.T.S.I. Telecomunicacion       Fax: +34 952 133361
Universidad de Malaga
Campus Universitario de Teatinos
29071 Malaga, Spain

http://www.isa.uma.es/jlblanco
___________________________________________________________

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

Re: Possible memory allocation bug

by Guy K. Kloss-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 03 Sep 2009 22:10:11 Jose Luis Blanco wrote:
> I've not been able to get a consistent test code, but I'm having
> program crashes (in Linux) and asserts (in Windows) when calling
> "cvGoodFeaturesToTrack".

It might help to to run the code under questioning through valgrind or compile
it with libefence to see whether there's some boundary violation.

Guy

--
Guy K. Kloss
Institute of Information and Mathematical Sciences
Te Kura Pūtaiao o Mōhiohio me Pāngarau
Massey University, Albany (North Shore City, Auckland)
473 State Highway 17, Gate 1, Mailroom, Quad B Building
voice: +64 9 414-0800 ext. 9585   fax: +64 9 441-8181
G.Kloss@... http://www.massey.ac.nz/~gkloss

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

Re: Possible memory allocation bug

by Jose Luis Blanco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Running the test program (attached in my last mail) with Valgrind
reveals a few invalid memory accesses upon the first call to
cvGoodFeaturesToTrack.
It's possible that the error only happens for some precise image
sizes, hence it passed unnoticed before...

I attach the log file.

Best,
JL



On Fri, Sep 4, 2009 at 2:52 AM, Guy K. Kloss<g.kloss@...> wrote:

> On Thu, 03 Sep 2009 22:10:11 Jose Luis Blanco wrote:
>> I've not been able to get a consistent test code, but I'm having
>> program crashes (in Linux) and asserts (in Windows) when calling
>> "cvGoodFeaturesToTrack".
>
> It might help to to run the code under questioning through valgrind or compile
> it with libefence to see whether there's some boundary violation.
>
> Guy
>
> --
> Guy K. Kloss
> Institute of Information and Mathematical Sciences
> Te Kura Pūtaiao o Mōhiohio me Pāngarau
> Massey University, Albany (North Shore City, Auckland)
> 473 State Highway 17, Gate 1, Mailroom, Quad B Building
> voice: +64 9 414-0800 ext. 9585   fax: +64 9 441-8181
> G.Kloss@... http://www.massey.ac.nz/~gkloss
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Opencvlibrary-devel mailing list
> Opencvlibrary-devel@...
> https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel
>


--

___________________________________________________________

Jose-Luis Blanco-Claraco      Phone: +34 952 132848
Dpto. Ingenieria de Sistemas y Automatica
E.T.S.I. Telecomunicacion       Fax: +34 952 133361
Universidad de Malaga
Campus Universitario de Teatinos
29071 Malaga, Spain

http://www.isa.uma.es/jlblanco
___________________________________________________________

[valgrind.log]

valgrind ./opencv_example

==9362== Memcheck, a memory error detector.
==9362== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==9362== Using LibVEX rev 1884, a library for dynamic binary translation.
==9362== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==9362== Using valgrind-3.4.1-Debian, a dynamic binary instrumentation framework.
==9362== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==9362== For more details, rerun with: -v
==9362==
0...
==9362== Invalid read of size 1
==9362==    at 0x4C28500: memcpy (mc_replace_strmem.c:402)
==9362==    by 0x539C9C3: cv::FilterEngine::start(cv::Size_<int>, cv::Rect_<int>, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x539CDD5: cv::FilterEngine::start(cv::Mat const&, cv::Rect_<int> const&, bool, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x53A600D: cv::FilterEngine::apply(cv::Mat const&, cv::Mat&, cv::Rect_<int> const&, cv::Point_<int>, bool) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C113: cv::morphOp(int, cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C7E9: cv::dilate(cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5382FD9: cv::goodFeaturesToTrack(cv::Mat const&, std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >&, int, double, double, cv::Mat const&, int, bool, double) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5383B53: cvGoodFeaturesToTrack (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x401968: test_cv_bug() (test.cpp:26)
==9362==    by 0x401A37: main (test.cpp:35)
==9362==  Address 0x108417bf is not stack'd, malloc'd or (recently) free'd
==9362==
==9362== Invalid read of size 1
==9362==    at 0x4C28508: memcpy (mc_replace_strmem.c:402)
==9362==    by 0x539C9C3: cv::FilterEngine::start(cv::Size_<int>, cv::Rect_<int>, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x539CDD5: cv::FilterEngine::start(cv::Mat const&, cv::Rect_<int> const&, bool, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x53A600D: cv::FilterEngine::apply(cv::Mat const&, cv::Mat&, cv::Rect_<int> const&, cv::Point_<int>, bool) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C113: cv::morphOp(int, cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C7E9: cv::dilate(cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5382FD9: cv::goodFeaturesToTrack(cv::Mat const&, std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >&, int, double, double, cv::Mat const&, int, bool, double) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5383B53: cvGoodFeaturesToTrack (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x401968: test_cv_bug() (test.cpp:26)
==9362==    by 0x401A37: main (test.cpp:35)
==9362==  Address 0x108417be is not stack'd, malloc'd or (recently) free'd
==9362==
==9362== Invalid read of size 1
==9362==    at 0x4C28512: memcpy (mc_replace_strmem.c:402)
==9362==    by 0x539C9C3: cv::FilterEngine::start(cv::Size_<int>, cv::Rect_<int>, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x539CDD5: cv::FilterEngine::start(cv::Mat const&, cv::Rect_<int> const&, bool, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x53A600D: cv::FilterEngine::apply(cv::Mat const&, cv::Mat&, cv::Rect_<int> const&, cv::Point_<int>, bool) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C113: cv::morphOp(int, cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C7E9: cv::dilate(cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5382FD9: cv::goodFeaturesToTrack(cv::Mat const&, std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >&, int, double, double, cv::Mat const&, int, bool, double) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5383B53: cvGoodFeaturesToTrack (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x401968: test_cv_bug() (test.cpp:26)
==9362==    by 0x401A37: main (test.cpp:35)
==9362==  Address 0x108417bd is not stack'd, malloc'd or (recently) free'd
==9362==
==9362== Invalid read of size 1
==9362==    at 0x4C2851C: memcpy (mc_replace_strmem.c:402)
==9362==    by 0x539C9C3: cv::FilterEngine::start(cv::Size_<int>, cv::Rect_<int>, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x539CDD5: cv::FilterEngine::start(cv::Mat const&, cv::Rect_<int> const&, bool, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x53A600D: cv::FilterEngine::apply(cv::Mat const&, cv::Mat&, cv::Rect_<int> const&, cv::Point_<int>, bool) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C113: cv::morphOp(int, cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C7E9: cv::dilate(cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5382FD9: cv::goodFeaturesToTrack(cv::Mat const&, std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >&, int, double, double, cv::Mat const&, int, bool, double) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5383B53: cvGoodFeaturesToTrack (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x401968: test_cv_bug() (test.cpp:26)
==9362==    by 0x401A37: main (test.cpp:35)
==9362==  Address 0x108417bc is not stack'd, malloc'd or (recently) free'd
==9362==
==9362== Invalid read of size 8
==9362==    at 0x547D163: cv::MorphRowFilter<cv::MaxOp<float>, cv::MorphRowFVec<cv::VMax32f> >::operator()(unsigned char const*, unsigned char*, int, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x539CB09: cv::FilterEngine::start(cv::Size_<int>, cv::Rect_<int>, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x539CDD5: cv::FilterEngine::start(cv::Mat const&, cv::Rect_<int> const&, bool, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x53A600D: cv::FilterEngine::apply(cv::Mat const&, cv::Mat&, cv::Rect_<int> const&, cv::Point_<int>, bool) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C113: cv::morphOp(int, cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C7E9: cv::dilate(cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5382FD9: cv::goodFeaturesToTrack(cv::Mat const&, std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >&, int, double, double, cv::Mat const&, int, bool, double) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5383B53: cvGoodFeaturesToTrack (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x401968: test_cv_bug() (test.cpp:26)
==9362==    by 0x401A37: main (test.cpp:35)
==9362==  Address 0x10844644 is 5,124 bytes inside a block of size 5,128 alloc'd
==9362==    at 0x4C2726C: operator new(unsigned long) (vg_replace_malloc.c:230)
==9362==    by 0x4F46B9F: std::vector<unsigned char, std::allocator<unsigned char> >::_M_fill_insert(__gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >, unsigned long, unsigned char const&) (in /usr/local/lib/libcxcore.so.1.1.1)
==9362==    by 0x539C8F2: cv::FilterEngine::start(cv::Size_<int>, cv::Rect_<int>, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x539CDD5: cv::FilterEngine::start(cv::Mat const&, cv::Rect_<int> const&, bool, int) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x53A600D: cv::FilterEngine::apply(cv::Mat const&, cv::Mat&, cv::Rect_<int> const&, cv::Point_<int>, bool) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C113: cv::morphOp(int, cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x548C7E9: cv::dilate(cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5382FD9: cv::goodFeaturesToTrack(cv::Mat const&, std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >&, int, double, double, cv::Mat const&, int, bool, double) (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x5383B53: cvGoodFeaturesToTrack (in /usr/local/lib/libcv.so.1.1.1)
==9362==    by 0x401968: test_cv_bug() (test.cpp:26)
==9362==    by 0x401A37: main (test.cpp:35)
OpenCV Error: Assertion failed (((size_t)_src[i] & 15) == 0) in operator(), file /home/jlblanco/code/opencv-svn/src/cv/cvmorph.cpp, line 260
terminate called after throwing an instance of 'cv::Exception'
==9362==
==9362== ERROR SUMMARY: 3841 errors from 5 contexts (suppressed: 8 from 1)
==9362== malloc/free: in use at exit: 13,543,360 bytes in 145 blocks.
==9362== malloc/free: 234 allocs, 89 frees, 29,751,434 bytes allocated.
==9362== For counts of detected errors, rerun with: -v
==9362== searching for pointers to 145 not-freed blocks.
==9362== checked 11,246,624 bytes.
==9362==
==9362== LEAK SUMMARY:
==9362==    definitely lost: 0 bytes in 0 blocks.
==9362==      possibly lost: 718 bytes in 15 blocks.
==9362==    still reachable: 13,542,642 bytes in 130 blocks.
==9362==         suppressed: 0 bytes in 0 blocks.
==9362== Rerun with --leak-check=full to see details of leaked memory.




------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

Re: Possible memory allocation bug

by Vadim Pisarevsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Jose Luis,

thank you for the sample code, I fixed the problem; please, take the updated cvfilter.cpp from SVN.

Regards,
Vadim

On Fri, Sep 4, 2009 at 11:33 AM, Jose Luis Blanco <joseluisblancoc@...> wrote:
Running the test program (attached in my last mail) with Valgrind
reveals a few invalid memory accesses upon the first call to
cvGoodFeaturesToTrack.
It's possible that the error only happens for some precise image
sizes, hence it passed unnoticed before...

I attach the log file.

Best,
JL



On Fri, Sep 4, 2009 at 2:52 AM, Guy K. Kloss<g.kloss@...> wrote:
> On Thu, 03 Sep 2009 22:10:11 Jose Luis Blanco wrote:
>> I've not been able to get a consistent test code, but I'm having
>> program crashes (in Linux) and asserts (in Windows) when calling
>> "cvGoodFeaturesToTrack".
>
> It might help to to run the code under questioning through valgrind or compile
> it with libefence to see whether there's some boundary violation.
>
> Guy
>
> --
> Guy K. Kloss
> Institute of Information and Mathematical Sciences
> Te Kura Pūtaiao o Mōhiohio me Pāngarau
> Massey University, Albany (North Shore City, Auckland)
> 473 State Highway 17, Gate 1, Mailroom, Quad B Building
> voice: +64 9 414-0800 ext. 9585   fax: +64 9 441-8181
> G.Kloss@... http://www.massey.ac.nz/~gkloss
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Opencvlibrary-devel mailing list
> Opencvlibrary-devel@...
> https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel
>



--

___________________________________________________________

Jose-Luis Blanco-Claraco      Phone: +34 952 132848
Dpto. Ingenieria de Sistemas y Automatica
E.T.S.I. Telecomunicacion       Fax: +34 952 133361
Universidad de Malaga
Campus Universitario de Teatinos
29071 Malaga, Spain

http://www.isa.uma.es/jlblanco
___________________________________________________________

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel