fixing issue pointed out by amatus
[oweals/gnunet.git] / src / datacache / plugin_datacache_postgres.c
index e1cf334ef967c7b823a44484a7112fa42ee32066..c9d6deaaa565149fb0d530b352bbe5fd6aa0da33 100644 (file)
@@ -267,10 +267,11 @@ init_connection (struct Plugin *plugin)
  */
 static int
 delete_by_rowid (struct Plugin *plugin,
-                unsigned int rowid)
+                uint32_t rowid)
 {
-  const char *paramValues[] = { (const char *) &rowid };
-  int paramLengths[] = { sizeof (rowid) };
+  uint32_t brow = htonl (rowid);
+  const char *paramValues[] = { (const char *) &brow };
+  int paramLengths[] = { sizeof (brow) };
   const int paramFormats[] = { 1 };
   PGresult *ret;
 
@@ -300,10 +301,10 @@ delete_by_rowid (struct Plugin *plugin,
  * @param discard_time when to discard the value in any case
  * @return 0 on error, number of bytes used otherwise
  */
-static uint32_t 
+static size_t 
 postgres_plugin_put (void *cls,
                     const GNUNET_HashCode * key,
-                    uint32_t size,
+                    size_t size,
                     const char *data,
                     enum GNUNET_BLOCK_Type type,
                     struct GNUNET_TIME_Absolute discard_time)
@@ -407,7 +408,10 @@ postgres_plugin_get (void *cls,
       return 0; 
     }
   if (iter == NULL)
-    return cnt;
+    {
+      PQclear (res);
+      return cnt;
+    }
   if ( (3 != PQnfields (res)) ||
        (sizeof (uint64_t) != PQfsize (res, 0)) ||
        (sizeof (uint32_t) != PQfsize (res, 1)))
@@ -566,8 +570,6 @@ libgnunet_plugin_datacache_postgres_done (void *cls)
   struct GNUNET_DATACACHE_PluginFunctions *api = cls;
   struct Plugin *plugin = api->cls;
 
-  fprintf (stderr,
-          "Unloading postgres plugin\n");
   PQfinish (plugin->dbh);
   GNUNET_free (plugin);
   GNUNET_free (api);