gpsd-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gpsd-users] libgpsmm and memory leaks


From: Robert Norris
Subject: Re: [gpsd-users] libgpsmm and memory leaks
Date: Fri, 3 Feb 2017 20:16:51 +0000

FYI:

The memory leak in the Qt build was found and the fix has been applied to the 
latest source code.

--
Be Seeing You - Rob.
If at first you don't succeed,
then skydiving isn't for you.

________________________________________
From: gpsd-users <address@hidden> on behalf of Michele Carignani 
<address@hidden>
Sent: 30 January 2017 15:21:23
To: gpsd users
Subject: Re: [gpsd-users] libgpsmm and memory leaks

Hello everybody,

I found some more information about gpsmm libraries distributed by Ubuntu in 
the man page<http://manpages.ubuntu.com/manpages/trusty/man3/libgpsmm.3.html>:

"The important difference between the libraries is that libgpsmm is targeted at 
C++ applications and contained in libgps, while libQgpsmm is platform 
independent by using QTcpSocket to connect to gpsd and shipped as an additional 
library due to the necessary linking to QT"

Therefore:
* libgps and libgps-dev ship gpsmm without Qt
* libqgpsmm and libqgpsmm-dev ship gpsmm with Qt

Since I didn't need Qt libraries, the fix for me was simply:
* to remove libqgpsmm* packages
* to link my program to libgps itself

Not a single line of code changed.
Re-running the dumb example above, now there aren't memory leaks (I paste 
Valgrind log below for completeness).

Thank you Jon for pointing me in the right direction.

Regards,
Michele



---------------------------------- NEW VALGRIND LOG
$ valgrind ./gpsd_cpp_client
==4498== Memcheck, a memory error detector
==4498== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==4498== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==4498== Command: ./gpsd_cpp_client
==4498==
==4498== Conditional jump or move depends on uninitialised value(s)
==4498==    at 0x4E4936A: gps_sock_read (in 
/usr/lib/x86_64-linux-gnu/libgps.so.20.0.0)
==4498==    by 0x4E45DA9: gps_read (in 
/usr/lib/x86_64-linux-gnu/libgps.so.20.0.0)
==4498==    by 0x4E4C064: gpsmm::read() (in 
/usr/lib/x86_64-linux-gnu/libgps.so.20.0.0)
==4498==    by 0x400DA4: main (in 
/home/miche/devel/experiments/c++/gpsd_cpp_client/gpsd_cpp_client)
==4498==
lat:nan, lon:nan
lat:nan, lon:nan
lat:nan, lon:nan
lat:nan, lon:nan
lat:nan, lon:nan
lat:43.7183, lon:10.4251
lat:43.7183, lon:10.4251
lat:43.7183, lon:10.4251
lat:43.7183, lon:10.4251
lat:43.7183, lon:10.4251
lat:43.7183, lon:10.4251
lat:43.7183, lon:10.4251
lat:43.7183, lon:10.4251
==4498==
==4498== HEAP SUMMARY:
==4498==     in use at exit: 0 bytes in 0 blocks
==4498==   total heap usage: 54 allocs, 54 frees, 31,913 bytes allocated
==4498==
==4498== All heap blocks were freed -- no leaks are possible
==4498==
==4498== For counts of detected and suppressed errors, rerun with: -v
==4498== Use --track-origins=yes to see where uninitialised values come from
==4498== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)


2017-01-30 14:16 GMT+01:00 Michele Carignani 
<address@hidden<mailto:address@hidden>>:
Hello Jon,

Thank you for replying.

No, I'm not targeting Qt environment myself, I'm working on some headless 
stuff, no GUI needed.
If I understand correctly the link is provided by default in the Ubuntu 
distributed version (which I have to deal with).

I will check if Ubuntu distributes libgpsmm without Qt and will report future 
experiments.

Thanks,รน
Michele

2017-01-30 12:31 GMT+01:00 Jon Schlueter 
<address@hidden<mailto:address@hidden>>:
Thanks for taking a look and reporting, First Question are you
targeting this for a QT application?

one comment inline, but it does not suprise me that there are leaks
with the QT hooks that have been embedded in the code.

Jon

On Mon, Jan 30, 2017 at 4:26 AM, Michele Carignani
<address@hidden<mailto:address@hidden>> wrote:
> Hello everybody,
>
> I'm using libgpsmm in my project and I detected some memory leaks in the
> function gps_open(). Do you think I'm using it wrong or is something within
> the library?
>
> Thank you for your help in advance :)
>
> My setup:
> Ubuntu 14.04 trusty
> gpsd 3.9 (ubuntu deb)
> libqgpsmm20:amd64 3.9-3 (ubuntu deb)
>
> How to reproduce:
> ------------------- CODE
> #include <libgpsmm.h>
> #include <iostream>
> #include <unistd.h>
>
> gpsmm* cli = NULL;
>
> #define GPS_HOST_NAME "localhost"
> #define  GPS_HOST_PORT "2947"
> #define GPS_WAITING_TIMEOUT 1000
>
> int main () {
>     cli = new gpsmm(GPS_HOST_NAME, GPS_HOST_PORT);
>     cli->stream(WATCH_ENABLE | WATCH_JSON | WATCH_NEWSTYLE | WATCH_SCALED);
>     gps_data_t* g;
>
>     for(int i = 0; i < 50; i++){
>         if(cli->waiting(GPS_WAITING_TIMEOUT)){
>             if( (g = cli->read()) ){
>                 std::cout << "lat:" <<  g->fix.latitude << ", lon:" <<
> g->fix.longitude << std::endl;
>             }
>         }
>
>         sleep(1);
>     }
>
>     cli->stream(WATCH_DISABLE);
>     delete(cli);
> }
>
> ------------------- ENDS CODE
>
> Compile:
> g++ -std=c++11 gpsd_cpp_client.cpp -o gpsd_cpp_client -lQgpsmm
>
>
> Valgrind log:
> $ valgrind --leak-check=full ./gpsd_cpp_client
> ==19300== Memcheck, a memory error detector
> ==19300== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
> ==19300== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
> ==19300== Command: ./gpsd_cpp_client
> ==19300==
> QObject::connect: Cannot connect (null)::destroyed() to
> QHostInfoLookupManager::waitForThreadPoolDone()
> libgps::connected!
> ==19300== Conditional jump or move depends on uninitialised value(s)
> ==19300==    at 0x4E4A4A2: gps_sock_read(gps_data_t*) (in
> /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x4E470CA: gps_read (in
> /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x4E4DB84: gpsmm::read() (in
> /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x400DA4: main (in
> /home/miche/devel/experiments/c++/gpsd_cpp_client/gpsd_cpp_client)
> ==19300==

This does not surprise me in the least, and we will have to look into
what the QT rules are around the calls used and what clean up we need
to inject.

> lat:nan, lon:nan
> lat:nan, lon:nan
> lat:nan, lon:nan
> lat:nan, lon:nan
> lat:43.7184, lon:10.424
> lat:43.7184, lon:10.424
> lat:43.7184, lon:10.424
> lat:43.7184, lon:10.424
> lat:43.7184, lon:10.424
> lat:43.7184, lon:10.424
> lat:43.7184, lon:10.424
> lat:43.7184, lon:10.424
> lat:43.7184, lon:10.4239
> lat:43.7184, lon:10.4239
> ==19300==
> ==19300== HEAP SUMMARY:
> ==19300==     in use at exit: 34,854 bytes in 77 blocks
> ==19300==   total heap usage: 797 allocs, 720 frees, 870,968 bytes allocated
> ==19300==
> ==19300== 196 (96 direct, 100 indirect) bytes in 1 blocks are definitely
> lost in loss record 52 of 69
> ==19300==    at 0x4C2B0E0: operator new(unsigned long) (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==19300==    by 0x6231D31: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x62322DD: QLibrary::setFileName(QString const&) (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x6232358: QLibrary::QLibrary(QString const&, QObject*) (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x5E300BF: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4.8.6)
> ==19300==    by 0x5E308EC: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4.8.6)
> ==19300==    by 0x5E25840: QHostInfo::fromName(QString const&) (in
> /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4.8.6)
> ==19300==    by 0x5E46969: QAbstractSocket::waitForConnected(int) (in
> /usr/lib/x86_64-linux-gnu/libQtNetwork.so.4.8.6)
> ==19300==    by 0x4E4ABCC: gps_sock_open(char const*, char const*,
> gps_data_t*) (in /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x4E46FC5: gps_open (in
> /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x4E4DA7A: gpsmm::gps_inner_open(char const*, char const*)
> (in /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x400F3C: gpsmm::gpsmm(char const*, char const*) (in
> /home/miche/devel/experiments/c++/gpsd_cpp_client/gpsd_cpp_client)
> ==19300==
> ==19300== 234 (96 direct, 138 indirect) bytes in 1 blocks are definitely
> lost in loss record 53 of 69
> ==19300==    at 0x4C2B0E0: operator new(unsigned long) (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==19300==    by 0x6231D31: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x62324DC: QLibrary::setFileNameAndVersion(QString const&,
> QString const&) (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x623252C: QLibrary::QLibrary(QString const&, QString
> const&, QObject*) (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x619BD44: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x616369B: QLocalePrivate::updateSystemPrivate() (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x616393A: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x61639B1: QLocale::QLocale() (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x618A33F: QString::toLongLong(bool*, int) const (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x618A488: QString::toInt(bool*, int) const (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x4E4AB64: gps_sock_open(char const*, char const*,
> gps_data_t*) (in /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x4E46FC5: gps_open (in
> /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==
> ==19300== 242 (96 direct, 146 indirect) bytes in 1 blocks are definitely
> lost in loss record 54 of 69
> ==19300==    at 0x4C2B0E0: operator new(unsigned long) (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==19300==    by 0x6231D31: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x62324DC: QLibrary::setFileNameAndVersion(QString const&,
> QString const&) (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x623252C: QLibrary::QLibrary(QString const&, QString
> const&, QObject*) (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x619BC1A: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x616369B: QLocalePrivate::updateSystemPrivate() (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x616393A: ??? (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x61639B1: QLocale::QLocale() (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x618A33F: QString::toLongLong(bool*, int) const (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x618A488: QString::toInt(bool*, int) const (in
> /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.6)
> ==19300==    by 0x4E4AB64: gps_sock_open(char const*, char const*,
> gps_data_t*) (in /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x4E46FC5: gps_open (in
> /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==
> ==19300== 8,216 bytes in 1 blocks are definitely lost in loss record 69 of
> 69
> ==19300==    at 0x4C2AB80: malloc (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==19300==    by 0x4E4ACF1: gps_sock_open(char const*, char const*,
> gps_data_t*) (in /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x4E46FC5: gps_open (in
> /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x4E4DA7A: gpsmm::gps_inner_open(char const*, char const*)
> (in /usr/lib/x86_64-linux-gnu/libQgpsmm.so.20.0.0)
> ==19300==    by 0x400F3C: gpsmm::gpsmm(char const*, char const*) (in
> /home/miche/devel/experiments/c++/gpsd_cpp_client/gpsd_cpp_client)
> ==19300==    by 0x400D56: main (in
> /home/miche/devel/experiments/c++/gpsd_cpp_client/gpsd_cpp_client)
> ==19300==
> ==19300== LEAK SUMMARY:
> ==19300==    definitely lost: 8,504 bytes in 4 blocks
> ==19300==    indirectly lost: 384 bytes in 8 blocks
> ==19300==      possibly lost: 0 bytes in 0 blocks
> ==19300==    still reachable: 25,966 bytes in 65 blocks
> ==19300==         suppressed: 0 bytes in 0 blocks
> ==19300== Reachable blocks (those to which a pointer was found) are not
> shown.
> ==19300== To see them, rerun with: --leak-check=full --show-leak-kinds=all
> ==19300==
> ==19300== For counts of detected and suppressed errors, rerun with: -v
> ==19300== Use --track-origins=yes to see where uninitialised values come
> from
> ==19300== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 from 0)
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]