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: Jon Schlueter
Subject: Re: [gpsd-users] libgpsmm and memory leaks
Date: Mon, 30 Jan 2017 06:31:04 -0500

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> 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]