OSDN Git Service

Avoid use of uninitialized variables
[pgstoreplans/pg_store_plans.git] / pg_store_plans.c
index 526617f..343f317 100644 (file)
@@ -83,8 +83,7 @@ static int max_plan_len = 5000;
 #define STICKY_DECREASE_FACTOR (0.50)  /* factor for sticky entries */
 #define USAGE_DEALLOC_PERCENT  5               /* free this % of entries at once */
 
-/* In PostgreSQL 11, queryid becomes a uint64 internally.
- */
+/* In PostgreSQL 11, queryid becomes a uint64 internally. */
 #if PG_VERSION_NUM >= 110000
 typedef uint64 queryid_t;
 #define PGSP_NO_QUERYID                UINT64CONST(0)
@@ -419,7 +418,7 @@ _PG_init(void)
                                                         &plan_storage,
                                                         PLAN_STORAGE_FILE,
                                                         plan_storage_options,
-                                                        PGC_USERSET,
+                                                        PGC_POSTMASTER,
                                                         0,
                                                         NULL,
                                                         NULL,
@@ -579,7 +578,7 @@ pgsp_shmem_startup(void)
 {
        bool            found;
        HASHCTL         info;
-       FILE       *file;
+       FILE       *file = NULL;
        FILE       *pfile = NULL;
        uint32          header;
        int32           num;
@@ -1471,15 +1470,19 @@ pg_store_plans_internal(FunctionCallInfo fcinfo,
                {
                        values[i++] = Int64GetDatumFast(queryid);
                        values[i++] = Int64GetDatumFast(planid);
+
+                       /* fill queryid_stat_statements with the same value with queryid */
                        if (api_version == PGSP_V1_5)
-                               values[i++] = ObjectIdGetDatum(queryid);
+                               values[i++] = Int64GetDatumFast(queryid);
                }
                else
                {
-                       values[i++] = Int64GetDatumFast(0);
-                       values[i++] = Int64GetDatumFast(0);
+                       nulls[i++] = true;      /* queryid */
+                       nulls[i++] = true;      /* planid */
+
+                       /* queryid_stat_statemetns*/
                        if (api_version == PGSP_V1_5)
-                               values[i++] = Int64GetDatumFast(0);
+                               nulls[i++] = true;
                }
 
                if (is_allowed_role || entry->key.userid == userid)
@@ -1509,6 +1512,7 @@ pg_store_plans_internal(FunctionCallInfo fcinfo,
                                        mstr = pgsp_json_xmlize(pstr);
                                        break;
                                default:
+                                       mstr = pstr;
                                        break;
                        }
 
@@ -1743,6 +1747,9 @@ entry_dealloc(void)
        entries = palloc(hash_get_num_entries(hash_table) * sizeof(pgspEntry *));
 
        i = 0;
+       tottextlen = 0;
+       nvalidtexts = 0;
+
        hash_seq_init(&hash_seq, hash_table);
        while ((entry = hash_seq_search(&hash_seq)) != NULL)
        {