Description: Copy route count before freeing memory
Author: Maxime Schoemans <maxime.schoemans@ulb.be>
Origin: upstream, https://github.com/MobilityDB/MobilityDB/commit/6e0e6572072c90dade2148d87ecaba6f5f072ddb
Last-Update: 2024-04-19
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/mobilitydb/src/npoint/tnpoint_gin.c
+++ b/mobilitydb/src/npoint/tnpoint_gin.c
@@ -75,9 +75,9 @@
   Datum *elems = palloc(sizeof(Datum) * routes->count);
   for (int i = 0; i < routes->count; i++)
     elems[i] = Int64GetDatum(SET_VAL_N(routes, i));
-  pfree(routes);
   *nkeys = routes->count;
   *nullFlags = NULL;
+  pfree(routes);
   PG_FREE_IF_COPY(temp, 0);
   PG_RETURN_POINTER(elems);
 }
@@ -127,9 +127,9 @@
       elems = palloc(sizeof(Datum) * routes->count);
       for (int i = 0; i < routes->count; i++)
         elems[i] = Int64GetDatum(SET_VAL_N(routes, i));
-      pfree(routes);
       *nkeys = routes->count;
       *searchMode = GIN_SEARCH_MODE_DEFAULT;
+      pfree(routes);
       PG_FREE_IF_COPY(temp, 0);
       break;
     default:
