gnucash maint: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Fri Apr 18 15:44:59 EDT 2014
Updated via https://github.com/Gnucash/gnucash/commit/52c07a54 (commit)
via https://github.com/Gnucash/gnucash/commit/b122141a (commit)
via https://github.com/Gnucash/gnucash/commit/b4b09752 (commit)
from https://github.com/Gnucash/gnucash/commit/4cf991a2 (commit)
commit 52c07a545d757700303675365def26eb64a1309c
Author: Moritz Lipp <mlq at pwmt.org>
Date: Thu Apr 17 01:36:55 2014 +0200
Correct usage of realloc in gnc_xml_be_get_file_lock
This patch fixes a common mistake where the return value of the function call
is set to the passed buffer and therefore previous allocated memory is lost if
the realloc call fails. Therefore a temporary variable is introduced and the
memory will be freed if the reallocation fails. In addition the return value of
the malloc allocation is checked.
diff --git a/src/backend/xml/gnc-backend-xml.c b/src/backend/xml/gnc-backend-xml.c
index 43fa1ff..6d9274e 100644
--- a/src/backend/xml/gnc-backend-xml.c
+++ b/src/backend/xml/gnc-backend-xml.c
@@ -104,7 +104,7 @@ gnc_xml_be_get_file_lock (FileBackend *be)
{
struct stat statbuf;
#ifndef G_OS_WIN32
- char *pathbuf = NULL, *path = NULL;
+ char *pathbuf = NULL, *path = NULL, *tmpbuf = NULL;
size_t pathbuf_size = 0;
#endif
int rc;
@@ -158,13 +158,22 @@ gnc_xml_be_get_file_lock (FileBackend *be)
#ifndef G_OS_WIN32
pathbuf_size = strlen (be->lockfile) + 100;
pathbuf = (char *) malloc (pathbuf_size);
+ if (pathbuf == NULL) {
+ return FALSE;
+ }
strcpy (pathbuf, be->lockfile);
path = strrchr (pathbuf, '.');
while (snprintf (path, pathbuf_size - (path - pathbuf), ".%lx.%d.LNK", gethostid(), getpid())
>= pathbuf_size - (path - pathbuf))
{
pathbuf_size += 100;
- pathbuf = (char *) realloc (pathbuf, pathbuf_size);
+ tmpbuf = (char *) realloc (pathbuf, pathbuf_size);
+ if (tmpbuf == NULL) {
+ free(pathbuf);
+ return FALSE;
+ } else {
+ pathbuf = tmpbuf;
+ }
}
rc = link (be->lockfile, pathbuf);
commit b122141a2cd1f5b1c68cb77090a9e43570c08fb5
Author: Moritz Lipp <mlq at pwmt.org>
Date: Tue Apr 15 19:59:16 2014 +0200
Make compatible to libdbi >= 0.9.0
Several functions of libdbi are now deprecated (e.g.: dbi_conn_new) and have
been replaced with _r functions (e.g.: dbi_conn_new_r) which now require a
dbi_instance passed as a parameter. This patch checks if the version of libdbi
is higher or equal than 0.9.0 and iff so, it uses the new _r functions instead
of the deprecated ones.
diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c
index 8347679..694cbba 100644
--- a/src/backend/dbi/gnc-backend-dbi.c
+++ b/src/backend/dbi/gnc-backend-dbi.c
@@ -67,6 +67,13 @@
#define GETPID() getpid()
#endif
+#if LIBDBI_VERSION >= 900
+#define HAVE_LIBDBI_R 1
+static dbi_inst dbi_instance;
+#else
+#define HAVE_LIBDBI_R 0
+#endif
+
/* For direct access to dbi data structs, sadly needed for datetime */
#include <dbi/dbi-dev.h>
@@ -283,7 +290,13 @@ gnc_dbi_sqlite3_session_begin( QofBackend *qbe, QofSession *session,
{
dbi_conn_close( be->conn );
}
+
+ #if HAVE_LIBDBI_R
+ be->conn = dbi_conn_new_r( "sqlite3", dbi_instance );
+ #else
be->conn = dbi_conn_new( "sqlite3" );
+ #endif
+
if ( be->conn == NULL )
{
PERR( "Unable to create sqlite3 dbi connection\n" );
@@ -808,7 +821,11 @@ gnc_dbi_mysql_session_begin( QofBackend* qbe, QofSession *session,
{
dbi_conn_close( be->conn );
}
+#if HAVE_LIBDBI_R
+ be->conn = dbi_conn_new_r( "mysql", dbi_instance );
+#else
be->conn = dbi_conn_new( "mysql" );
+#endif
if ( be->conn == NULL )
{
PERR( "Unable to create mysql dbi connection\n" );
@@ -893,7 +910,12 @@ gnc_dbi_mysql_session_begin( QofBackend* qbe, QofSession *session,
dbi_conn_close( be->conn );
// Try again to connect to the db
+ #if HAVE_LIBDBI_R
+ be->conn = dbi_conn_new_r( "mysql", dbi_instance );
+ #else
be->conn = dbi_conn_new( "mysql" );
+ #endif
+
if ( be->conn == NULL )
{
PERR( "Unable to create mysql dbi connection\n" );
@@ -1144,7 +1166,13 @@ gnc_dbi_postgres_session_begin( QofBackend *qbe, QofSession *session,
{
dbi_conn_close( be->conn );
}
+
+ #if HAVE_LIBDBI_R
+ be->conn = dbi_conn_new_r( "pgsql", dbi_instance );
+ #else
be->conn = dbi_conn_new( "pgsql" );
+ #endif
+
if ( be->conn == NULL )
{
PERR( "Unable to create pgsql dbi connection\n" );
@@ -1230,7 +1258,12 @@ gnc_dbi_postgres_session_begin( QofBackend *qbe, QofSession *session,
dbi_conn_close( be->conn );
// Try again to connect to the db
+ #if HAVE_LIBDBI_R
+ be->conn = dbi_conn_new_r( "pgsql", dbi_instance );
+ #else
be->conn = dbi_conn_new( "pgsql" );
+ #endif
+
if ( be->conn == NULL )
{
PERR( "Unable to create pgsql dbi connection\n" );
@@ -1835,7 +1868,11 @@ gnc_module_init_backend_dbi(void)
}
/* dbi_initialize returns -1 in case of errors */
+ #if HAVE_LIBDBI_R
+ num_drivers = dbi_initialize_r( driver_dir, dbi_instance );
+ #else
num_drivers = dbi_initialize( driver_dir );
+ #endif
if ( num_drivers <= 0 )
{
PWARN( "No DBD drivers found\n" );
@@ -1847,7 +1884,12 @@ gnc_module_init_backend_dbi(void)
do
{
+ #if HAVE_LIBDBI_R
+ driver = dbi_driver_list_r( driver, dbi_instance );
+ #else
driver = dbi_driver_list( driver );
+ #endif
+
if ( driver != NULL )
{
const gchar* name = dbi_driver_get_name( driver );
@@ -1945,7 +1987,11 @@ qof_backend_module_finalize( void )
void
gnc_module_finalize_backend_dbi( void )
{
+ #if HAVE_LIBDBI_R
+ dbi_shutdown_r(dbi_instance);
+ #else
dbi_shutdown();
+ #endif
}
/* --------------------------------------------------------- */
diff --git a/src/backend/dbi/test/test-backend-dbi-basic.c b/src/backend/dbi/test/test-backend-dbi-basic.c
index 46df960..d7e88eb 100644
--- a/src/backend/dbi/test/test-backend-dbi-basic.c
+++ b/src/backend/dbi/test/test-backend-dbi-basic.c
@@ -34,6 +34,13 @@
#include <gnc-prefs.h>
#include <qofsession-p.h>
+#if LIBDBI_VERSION >= 900
+#define HAVE_LIBDBI_R 1
+static dbi_inst dbi_instance;
+#else
+#define HAVE_LIBDBI_R 0
+#endif
+
static const gchar* suitename = "/backend/dbi";
void test_suite_gnc_backend_dbi (void);
@@ -230,9 +237,17 @@ destroy_database (gchar* url)
gnc_uri_get_components (url, &protocol, &host, &portnum,
&username, &password, &dbname);
if (g_strcmp0 (protocol, "postgres") == 0)
- conn = dbi_conn_new (pgsql);
+ #if HAVE_LIBDBI_R
+ conn = dbi_conn_new_r( pgsql, dbi_instance );
+ #else
+ conn = dbi_conn_new( pgsql );
+ #endif
else
+ #if HAVE_LIBDBI_R
+ conn = dbi_conn_new_r (protocol, dbi_instance);
+ #else
conn = dbi_conn_new (protocol);
+ #endif
port = g_strdup_printf ("%d", portnum);
if (conn == NULL)
{
@@ -581,7 +596,11 @@ test_suite_gnc_backend_dbi (void)
{
dbi_driver driver = NULL;
GList *drivers = NULL;
+ #if HAVE_LIBDBI_R
+ while ((driver = dbi_driver_list_r (driver, dbi_instance)))
+ #else
while ((driver = dbi_driver_list (driver)))
+ #endif
{
drivers = g_list_prepend (drivers,
(gchar*)dbi_driver_get_name (driver));
commit b4b097529eb54da64a9040c91ac511dc077d6651
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Apr 13 15:54:15 2014 -0700
Re-enable loading and saving gnucashdotdir/accelerator-home on OSX
Per user request. Permits user to customize the accelerator map and have the result
survive upgrades. Loads gnucashdotdir/accelerator-home if it exists, otherwise loads
share/gnucash/ui/osx_accel_map.
diff --git a/src/gnome-utils/gnc-gnome-utils.c b/src/gnome-utils/gnc-gnome-utils.c
index feeb03b..02bed11 100644
--- a/src/gnome-utils/gnc-gnome-utils.c
+++ b/src/gnome-utils/gnc-gnome-utils.c
@@ -709,9 +709,14 @@ gnc_gui_init(void)
gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
#ifdef MAC_INTEGRATION
- data_dir = gnc_path_get_pkgdatadir();
- map = g_build_filename(data_dir, "ui", "osx_accel_map", NULL);
- g_free(data_dir);
+ map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
+ if (!g_file_test (map, G_FILE_TEST_EXISTS))
+ {
+ g_free (map);
+ data_dir = gnc_path_get_pkgdatadir();
+ map = g_build_filename(data_dir, "ui", "osx_accel_map", NULL);
+ g_free(data_dir);
+ }
#else
map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
#endif /* MAC_INTEGRATION */
@@ -748,11 +753,9 @@ gnc_gui_shutdown (void)
if (gnome_is_running && !gnome_is_terminating)
{
gnome_is_terminating = TRUE;
-#ifndef MAC_INTEGRATION
map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
gtk_accel_map_save(map);
g_free(map);
-#endif /* MAC_INTEGRATION */
gtk_main_quit();
}
}
Summary of changes:
src/backend/dbi/gnc-backend-dbi.c | 46 +++++++++++++++++++++++++++
src/backend/dbi/test/test-backend-dbi-basic.c | 21 +++++++++++-
src/backend/xml/gnc-backend-xml.c | 13 ++++++--
src/gnome-utils/gnc-gnome-utils.c | 13 +++++---
4 files changed, 85 insertions(+), 8 deletions(-)
More information about the gnucash-changes
mailing list