• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MerginMaps / geodiff / 20338716598

18 Dec 2025 01:34PM UTC coverage: 88.019% (-0.3%) from 88.298%
20338716598

push

github

wonder-sk
Fix memory leaks on Postgres connection failure

0 of 3 new or added lines in 1 file covered. (0.0%)

90 existing lines in 2 files now uncovered.

3607 of 4098 relevant lines covered (88.02%)

577.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.13
/geodiff/src/drivers/postgresutils.cpp
1
/*
2
 GEODIFF - MIT License
3
 Copyright (C) 2020 Martin Dobias
4
*/
5

6
#include "postgresutils.h"
7
#include "geodiffutils.hpp"
8

9
GeoDiffPostgresException::GeoDiffPostgresException( PGresult *res, const std::string &sql )
1✔
10
  : GeoDiffPostgresException( PostgresResult( res ), sql ) {}
1✔
11

12
GeoDiffPostgresException::GeoDiffPostgresException( PostgresResult res, const std::string &sql )
1✔
13
  : GeoDiffException( "postgres cmd error(" + res.sqlState() +
2✔
14
                      "): " + res.statusErrorMessage() +
4✔
15
                      ( sql.size() ? "\n\nSQL:\n" + sql : "" ) ),
2✔
16
    mSql( sql ), mRes( std::move( res ) ) {}
3✔
17

18
const PostgresResult &GeoDiffPostgresException::result() const
1✔
19
{
20
  return mRes;
1✔
21
}
22

23
PostgresResult execSql( PGconn *c, const std::string &sql )
1,197✔
24
{
25
  PGresult *res = ::PQexec( c, sql.c_str() );
1,197✔
26

27
  if ( res && ::PQstatus( c ) == CONNECTION_OK )
1,197✔
28
  {
29
    int errorStatus = PQresultStatus( res );
1,197✔
30
    if ( errorStatus != PGRES_COMMAND_OK && errorStatus != PGRES_TUPLES_OK )
1,197✔
31
    {
32
      throw GeoDiffPostgresException( res, sql );
1✔
33
    }
34

35
    return PostgresResult( res );
1,196✔
36
  }
UNCOV
37
  if ( PQstatus( c ) != CONNECTION_OK )
×
38
  {
UNCOV
39
    if ( res )
×
UNCOV
40
      PQclear( res );
×
UNCOV
41
    throw GeoDiffException( "postgres conn error: " + std::string( PQerrorMessage( c ) ) );
×
42
  }
43
  else
44
  {
UNCOV
45
    throw GeoDiffException( "postgres error: out of memory" );
×
46
  }
47

48
  return PostgresResult( nullptr );
49
}
50

51
std::string quotedIdentifier( const std::string &ident )
1,990✔
52
{
53
  std::string result = replace( ident, "\"", "\"\"" );
5,970✔
54
  return "\"" + result + "\"";
3,980✔
55
}
1,990✔
56

57
std::string quotedString( const std::string &value )
935✔
58
{
59
  std::string result = replace( value, "'", "''" );
2,805✔
60
  if ( result.find( '\\' ) != std::string::npos )
935✔
61
  {
UNCOV
62
    result = replace( result, "\\", "\\\\" );
×
UNCOV
63
    return "E'" + result + "'";
×
64
  }
65
  else
66
    return "'" +  result + "'";
935✔
67
}
935✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc