PostgreSQL Source Code  git master
fe_memutils.c File Reference
#include "postgres_fe.h"
Include dependency graph for fe_memutils.c:

Go to the source code of this file.

Functions

static void * pg_malloc_internal (size_t size, int flags)
 
void * pg_malloc (size_t size)
 
void * pg_malloc0 (size_t size)
 
void * pg_malloc_extended (size_t size, int flags)
 
void * pg_realloc (void *ptr, size_t size)
 
char * pg_strdup (const char *in)
 
void pg_free (void *ptr)
 
void * palloc (Size size)
 
void * palloc0 (Size size)
 
void * palloc_extended (Size size, int flags)
 
void pfree (void *pointer)
 
char * pstrdup (const char *in)
 
void * repalloc (void *pointer, Size size)
 

Function Documentation

◆ palloc()

◆ palloc0()

◆ palloc_extended()

◆ pfree()

void pfree ( void *  pointer)

Definition at line 134 of file fe_memutils.c.

References MemoryContextMethods::free_p, GetMemoryChunkContext(), MemoryContextData::methods, pg_free(), and VALGRIND_MEMPOOL_FREE.

135 {
136  pg_free(pointer);
137 }
void pg_free(void *ptr)
Definition: fe_memutils.c:105

◆ pg_free()

◆ pg_malloc()

void* pg_malloc ( size_t  size)

Definition at line 47 of file fe_memutils.c.

References pg_malloc_internal().

Referenced by _Clone(), _CustomReadFunc(), _PrintFileData(), _skipData(), add_one_elt(), add_stringlist_item(), addObjectDependency(), ahprintf(), ArchiveEntry(), archprintf(), AssignDumpId(), avlInsertNode(), BuildArchiveDependencies(), buildIndexArray(), cfopen(), CloneArchive(), collectComments(), collectSecLabels(), conditional_stack_create(), conditional_stack_push(), copyFile(), createBoundaryObjects(), CreateVariableSpace(), CreateWalTarMethod(), datapagemap_iterate(), do_connect(), do_watch(), EndCompressor(), exec_command_prompt(), ExecuteSqlCommandBuf(), filemap_create(), filter_lines_with_token(), find_other_exec_or_die(), findDependencyLoops(), findParentsByOid(), fix_dependencies(), flagInhAttrs(), format_numeric_locale(), gen_db_file_maps(), get_comma_elts(), get_db_infos(), get_loadable_libraries(), get_rel_infos(), get_sock_dir(), get_tablespace_paths(), getAccessMethods(), getAggregates(), getBlobs(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDomainConstraints(), getDumpableObjects(), getEventTriggers(), getExtendedStatistics(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getInherits(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPolicies(), getProcLangs(), getPublications(), getPublicationTables(), getRules(), getSubscriptions(), getTableAttrs(), getTimelineHistory(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), identify_locking_dependencies(), InitArchiveFmt_Custom(), InitArchiveFmt_Directory(), InitArchiveFmt_Null(), InitArchiveFmt_Tar(), libpqGetFile(), load_resultmap(), lookupCreateVariable(), main(), makeTableDataInfo(), NewDumpOptions(), parallel_exec_prog(), parallel_transfer_all_new_dbs(), ParallelBackupStart(), ParseScript(), parseScriptWeight(), parseVariable(), pg_attribute_unused(), pretty_wal_size(), print_aligned_text(), print_aligned_vertical(), printCrosstab(), PrintResultsInCrosstab(), process_source_file(), process_sql_command(), process_target_file(), pset_quoted_string(), quote_identifier(), quote_if_needed(), rankSort(), read_file_contents(), ReadControlFile(), ReadDataFromArchiveNone(), readfile(), readMessageFromPipe(), ReadStr(), ReadToc(), receiveFileChunks(), replace_token(), rewind_parseTimeLineHistory(), rewriteVisibilityMap(), run_all_permutations(), run_named_permutations(), run_permutation(), setalarm(), setup_bin_paths(), SetVariable(), SetVariableHooks(), SetWALSegSize(), simple_action_list_append(), simple_oid_list_append(), simple_string_list_append(), slurpFile(), sortDumpableObjects(), SortTocFromFile(), sql_exec(), sql_exec_searchtables(), strtokx(), tar_open_for_write(), tarPrintf(), TopoSort(), vacuum_one_database(), wait_for_tests(), WaitForTerminatingWorkers(), and WriteEmptyXLOG().

48 {
49  return pg_malloc_internal(size, 0);
50 }
static void * pg_malloc_internal(size_t size, int flags)
Definition: fe_memutils.c:23

◆ pg_malloc0()

◆ pg_malloc_extended()

void* pg_malloc_extended ( size_t  size,
int  flags 
)

Definition at line 59 of file fe_memutils.c.

References pg_malloc_internal().

60 {
61  return pg_malloc_internal(size, flags);
62 }
static void * pg_malloc_internal(size_t size, int flags)
Definition: fe_memutils.c:23

◆ pg_malloc_internal()

static void* pg_malloc_internal ( size_t  size,
int  flags 
)
inlinestatic

Definition at line 23 of file fe_memutils.c.

References _, EXIT_FAILURE, malloc, MCXT_ALLOC_NO_OOM, MCXT_ALLOC_ZERO, and MemSet.

Referenced by palloc(), palloc0(), palloc_extended(), pg_malloc(), pg_malloc0(), and pg_malloc_extended().

24 {
25  void *tmp;
26 
27  /* Avoid unportable behavior of malloc(0) */
28  if (size == 0)
29  size = 1;
30  tmp = malloc(size);
31  if (tmp == NULL)
32  {
33  if ((flags & MCXT_ALLOC_NO_OOM) == 0)
34  {
35  fprintf(stderr, _("out of memory\n"));
36  exit(EXIT_FAILURE);
37  }
38  return NULL;
39  }
40 
41  if ((flags & MCXT_ALLOC_ZERO) != 0)
42  MemSet(tmp, 0, size);
43  return tmp;
44 }
#define MCXT_ALLOC_NO_OOM
Definition: fe_memutils.h:18
#define MemSet(start, val, len)
Definition: c.h:853
#define malloc(a)
Definition: header.h:50
#define MCXT_ALLOC_ZERO
Definition: fe_memutils.h:19
#define EXIT_FAILURE
Definition: settings.h:152
#define _(x)
Definition: elog.c:84

◆ pg_realloc()

void* pg_realloc ( void *  ptr,
size_t  size 
)

Definition at line 65 of file fe_memutils.c.

References _, EXIT_FAILURE, and realloc.

Referenced by add_one_elt(), addObjectDependency(), AssignDumpId(), BuildArchiveDependencies(), datapagemap_add(), exec_command_set(), filemap_list_to_array(), findDumpableDependencies(), identify_locking_dependencies(), lookupCreateVariable(), main(), ParseScript(), read_file_contents(), readMessageFromPipe(), ReadToc(), repalloc(), replaceVariable(), and rewind_parseTimeLineHistory().

66 {
67  void *tmp;
68 
69  /* Avoid unportable behavior of realloc(NULL, 0) */
70  if (ptr == NULL && size == 0)
71  size = 1;
72  tmp = realloc(ptr, size);
73  if (!tmp)
74  {
75  fprintf(stderr, _("out of memory\n"));
76  exit(EXIT_FAILURE);
77  }
78  return tmp;
79 }
#define realloc(a, b)
Definition: header.h:60
#define EXIT_FAILURE
Definition: settings.h:152
#define _(x)
Definition: elog.c:84

◆ pg_strdup()

char* pg_strdup ( const char *  in)

Definition at line 85 of file fe_memutils.c.

References _, and EXIT_FAILURE.

Referenced by _allocAH(), _ArchiveEntry(), _becomeUser(), _check_database_version(), _connectDB(), _getObjectDescription(), _printTocEntry(), _selectOutputSchema(), _selectTablespace(), _tarGetHeader(), add_one_elt(), add_stringlist_item(), adjust_data_dir(), ArchiveEntry(), bool_substitute_hook(), bootstrap_template1(), check_locale_name(), check_required_directory(), CloneArchive(), comp_keyword_case_substitute_hook(), ConnectDatabase(), constructConnStr(), convertOperatorReference(), convertRegProcReference(), convertTSFunction(), create_script_for_old_cluster_deletion(), createBoundaryObjects(), CreateWalDirectoryMethod(), describeOneTableDetails(), describeRoles(), dir_open_for_write(), do_connect(), do_pset(), dumpAccessMethod(), dumpBaseType(), dumpCompositeType(), dumpCreateDB(), dumpDomain(), dumpEnumType(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpGroups(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpProcLang(), dumpRangeType(), dumpTable(), dumpTableSchema(), dumpTablespaces(), dumpUndefinedType(), echo_substitute_hook(), encodingid_to_string(), exec_command_g(), exec_command_gset(), exec_command_set(), fetch_count_substitute_hook(), find_matching_ts_config(), fix_path_separator(), flagInhAttrs(), format_numeric_locale(), get_canonical_locale_name(), get_comma_elts(), get_control_data(), get_db_infos(), get_id(), get_language_name(), get_loadable_libraries(), get_opts(), get_prompt(), get_rel_infos(), get_restricted_token(), get_sock_dir(), get_su_pwd(), get_synchronized_snapshot(), get_tablespace_paths(), get_user_info(), getAccessMethods(), getAggregates(), getBlobs(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFormattedTypeName(), getFuncs(), getIndexes(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPolicies(), getProcLangs(), getPublications(), getPublicationTables(), getRules(), gets_fromFile(), getSubscriptions(), getTableAttrs(), getTables(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), getVariable(), histcontrol_substitute_hook(), histsize_substitute_hook(), ignoreeof_substitute_hook(), initializeInput(), load_resultmap(), locale_date_order(), lookupCreateVariable(), main(), MainLoop(), makeAlterConfigCommand(), open_result_files(), parallel_exec_prog(), parallel_transfer_all_new_dbs(), parse_psql_options(), parse_slash_copy(), parseCommandLine(), parseQuery(), parseScriptWeight(), pg_send_history(), printTableAddFooter(), printTableSetFooter(), PrintTOCSummary(), process_backslash_command(), process_source_file(), process_sql_command(), process_target_file(), processEncodingEntry(), processExtensionTables(), prompt_for_password(), psql_get_variable(), pstrdup(), putVariable(), read_post_opts(), readfile(), regression_main(), replace_line_endings(), replace_string(), RestoreArchive(), run_schedule(), run_simple_query(), RunIdentifySystem(), sendCommand(), set_info_version(), set_tablespace_directory_suffix(), setDecimalLocale(), setup(), setup_config(), setup_connection(), setup_pgdata(), SetVariable(), SetVariableHooks(), show_context_substitute_hook(), simple_action_list_append(), split_path(), split_to_stringlist(), stop_postmaster(), tar_open_for_write(), tarOpen(), try_complete_step(), and verbosity_substitute_hook().

86 {
87  char *tmp;
88 
89  if (!in)
90  {
91  fprintf(stderr,
92  _("cannot duplicate null pointer (internal error)\n"));
93  exit(EXIT_FAILURE);
94  }
95  tmp = strdup(in);
96  if (!tmp)
97  {
98  fprintf(stderr, _("out of memory\n"));
99  exit(EXIT_FAILURE);
100  }
101  return tmp;
102 }
#define EXIT_FAILURE
Definition: settings.h:152
#define _(x)
Definition: elog.c:84

◆ pstrdup()

char* pstrdup ( const char *  in)

Definition at line 140 of file fe_memutils.c.

References MemoryContextStrdup(), and pg_strdup().

Referenced by MemoryContextSwitchTo().

141 {
142  return pg_strdup(in);
143 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85

◆ repalloc()

void* repalloc ( void *  pointer,
Size  size 
)