/* Estimate space for query text. */
query_len = strlen(estate->es_sourceText);
- shm_toc_estimate_chunk(&pcxt->estimator, query_len);
+ shm_toc_estimate_chunk(&pcxt->estimator, query_len + 1);
shm_toc_estimate_keys(&pcxt->estimator, 1);
/* Estimate space for serialized PlannedStmt. */
shm_toc_insert(pcxt->toc, PARALLEL_KEY_EXECUTOR_FIXED, fpes);
/* Store query string */
- query_string = shm_toc_allocate(pcxt->toc, query_len);
- memcpy(query_string, estate->es_sourceText, query_len);
+ query_string = shm_toc_allocate(pcxt->toc, query_len + 1);
+ memcpy(query_string, estate->es_sourceText, query_len + 1);
shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, query_string);
/* Store serialized PlannedStmt. */