find . -type f -iname '*.c' -exec egrep -C5 '[^a-z_](malloc|realloc|strdup)' {} + | less /(malloc|realloc|strdup) ./contrib/pg_standby/pg_standby.c- case 't': /* Trigger file */ ./contrib/pg_standby/pg_standby.c: triggerPath = strdup(optarg); ./contrib/pg_standby/pg_standby.c- break; ./contrib/spi/refint.c: plan->splan = (SPIPlanPtr *) malloc(sizeof(SPIPlanPtr)); ./contrib/spi/refint.c- *(plan->splan) = pplan; ./contrib/spi/refint.c- plan->nplans = 1; ./contrib/spi/refint.c: plan->splan = (SPIPlanPtr *) malloc(nrefs * sizeof(SPIPlanPtr)); ./contrib/spi/refint.c- ./contrib/spi/refint.c- for (r = 0; r < nrefs; r++) ./contrib/spi/refint.c- { ./contrib/spi/refint.c- relname = args2[0]; ./contrib/spi/refint.c- ./contrib/spi/refint.c- if (strcmp((*eplan)[i].ident, ident) == 0) ./contrib/spi/refint.c- break; ./contrib/spi/refint.c- } ./contrib/spi/refint.c- if (i != *nplans) ./contrib/spi/refint.c- return (*eplan + i); ./contrib/spi/refint.c: *eplan = (EPlan *) realloc(*eplan, (i + 1) * sizeof(EPlan)); ./contrib/spi/refint.c- newp = *eplan + i; ./contrib/spi/refint.c- } ./contrib/spi/refint.c- else ./contrib/spi/refint.c- { ./contrib/spi/refint.c: newp = *eplan = (EPlan *) malloc(sizeof(EPlan)); ./contrib/spi/refint.c- (*nplans) = i = 0; ./contrib/spi/refint.c- } ./contrib/spi/refint.c- ./contrib/spi/refint.c- newp->ident = strdup(ident); ./contrib/spi/refint.c- newp->nplans = 0; ./contrib/spi/timetravel.c- if (i != *nplans) ./contrib/spi/timetravel.c- return (*eplan + i); ./contrib/spi/timetravel.c: *eplan = (EPlan *) realloc(*eplan, (i + 1) * sizeof(EPlan)); ./contrib/spi/timetravel.c- newp = *eplan + i; ./contrib/spi/timetravel.c- } ./contrib/spi/timetravel.c- else ./contrib/spi/timetravel.c- { ./contrib/spi/timetravel.c: newp = *eplan = (EPlan *) malloc(sizeof(EPlan)); ./contrib/spi/timetravel.c- (*nplans) = i = 0; ./contrib/spi/timetravel.c- } ./contrib/spi/timetravel.c- ./contrib/spi/timetravel.c- newp->ident = strdup(ident); ./contrib/spi/timetravel.c- newp->splan = NULL; ./contrib/vacuumlo/vacuumlo.c- case 'U': ./contrib/vacuumlo/vacuumlo.c: param.pg_user = strdup(optarg); ./contrib/vacuumlo/vacuumlo.c- break; ./contrib/vacuumlo/vacuumlo.c- case 'w': ./contrib/vacuumlo/vacuumlo.c- param.pg_prompt = TRI_NO; ./contrib/vacuumlo/vacuumlo.c- break; ./contrib/vacuumlo/vacuumlo.c- case 'W': -- ./contrib/vacuumlo/vacuumlo.c- if ((port < 1) || (port > 65535)) ./contrib/vacuumlo/vacuumlo.c- { ./contrib/vacuumlo/vacuumlo.c- fprintf(stderr, "%s: invalid port number: %s\n", progname, optarg); ./contrib/vacuumlo/vacuumlo.c- exit(1); ./contrib/vacuumlo/vacuumlo.c- } ./contrib/vacuumlo/vacuumlo.c: param.pg_port = strdup(optarg); ./contrib/vacuumlo/vacuumlo.c- break; ./contrib/vacuumlo/vacuumlo.c- case 'h': ./contrib/vacuumlo/vacuumlo.c: param.pg_host = strdup(optarg); ./contrib/vacuumlo/vacuumlo.c- break; ./contrib/vacuumlo/vacuumlo.c- } ./contrib/vacuumlo/vacuumlo.c- } ./contrib/vacuumlo/vacuumlo.c- ./contrib/vacuumlo/vacuumlo.c- /* No database given? Show usage */ ./src/backend/bootstrap/bootstrap.c- case 'D': ./src/backend/bootstrap/bootstrap.c: userDoption = strdup(optarg); ./src/backend/bootstrap/bootstrap.c- break; ./src/backend/bootstrap/bootstrap.c- case 'd': ./src/backend/bootstrap/bootstrap.c- { ./src/backend/main/main.c- else if (argc > 1 && strcmp(argv[1], "--single") == 0) ./src/backend/main/main.c- PostgresMain(argc, argv, ./src/backend/main/main.c- NULL, /* no dbname */ ./src/backend/main/main.c: strdup(get_user_name_or_exit(progname))); /* does not return */ ./src/backend/postmaster/postmaster.c- case 'C': ./src/backend/postmaster/postmaster.c: output_config_variable = strdup(optarg); ./src/backend/postmaster/postmaster.c- break; ./src/backend/postmaster/postmaster.c- ./src/backend/postmaster/postmaster.c- case 'D': ./src/backend/postmaster/postmaster.c: userDoption = strdup(optarg); ./src/backend/postmaster/postmaster.c- break; ./src/backend/postmaster/postmaster.c- ./src/backend/postmaster/postmaster.c- ./src/backend/postmaster/postmaster.c- /* ./src/backend/postmaster/postmaster.c- * Save remote_host and remote_port in port structure (after this, they ./src/backend/postmaster/postmaster.c- * will appear in log_line_prefix data for log messages). ./src/backend/postmaster/postmaster.c- */ ./src/backend/postmaster/postmaster.c: port->remote_host = strdup(remote_host); ./src/backend/postmaster/postmaster.c: port->remote_port = strdup(remote_port); ./src/backend/postmaster/postmaster.c- ./src/backend/postmaster/postmaster.c- */ ./src/backend/postmaster/postmaster.c- if (log_hostname && ./src/backend/postmaster/postmaster.c- ret == 0 && ./src/backend/postmaster/postmaster.c- strspn(remote_host, "0123456789.") < strlen(remote_host) && ./src/backend/postmaster/postmaster.c- strspn(remote_host, "0123456789ABCDEFabcdef:") < strlen(remote_host)) ./src/backend/postmaster/postmaster.c: port->remote_hostname = strdup(remote_host); ./src/backend/postmaster/postmaster.c- ./src/backend/tcop/postgres.c- case 'D': ./src/backend/tcop/postgres.c- if (secure) ./src/backend/tcop/postgres.c: userDoption = strdup(optarg); ./src/backend/tcop/postgres.c- break; ./src/backend/tcop/postgres.c- ./src/backend/tcop/postgres.c- case 'd': ./src/backend/tcop/postgres.c- set_debug_options(atoi(optarg), ctx, gucsource); ./src/backend/tcop/postgres.c- break; ./src/backend/tcop/postgres.c- if (!errs && dbname && *dbname == NULL && argc - optind >= 1) ./src/backend/tcop/postgres.c: *dbname = strdup(argv[optind++]); ./src/backend/tcop/postgres.c- ./src/backend/tcop/postgres.c- if (errs || argc != optind) ./src/backend/tcop/postgres.c- { ./src/backend/tcop/postgres.c- if (errs) ./src/backend/tcop/postgres.c- optind--; /* complain about the previous argument */ ./src/backend/utils/adt/pg_locale.c: grouping = strdup(extlconv->grouping); ./src/backend/utils/adt/pg_locale.c- ./src/backend/utils/adt/pg_locale.c-#ifdef WIN32 ./src/backend/utils/adt/pg_locale.c- /* use monetary to set the ctype */ ./src/backend/utils/adt/pg_locale.c- setlocale(LC_CTYPE, locale_monetary); ./src/backend/utils/adt/pg_locale.c-#endif ./src/backend/utils/adt/pg_locale.c: CurrentLocaleConv.mon_grouping = strdup(extlconv->mon_grouping); ++ pg_locale.c (result is never checked by caller): static char * db_encoding_strdup(int encoding, const char *str) { char *pstr; char *mstr; /* convert the string to the database encoding */ pstr = pg_any_to_server(str, strlen(str), encoding); mstr = strdup(pstr); if (pstr != str) pfree(pstr); return mstr; } ./src/backend/utils/error/elog.c: syslog_ident = strdup(ident); ./src/backend/utils/mmgr/mcxt.c- { ./src/backend/utils/mmgr/mcxt.c: /* Special case for startup: use good ol' malloc */ ./src/backend/utils/mmgr/mcxt.c: node = (MemoryContext) malloc(needed); ./src/backend/utils/mmgr/mcxt.c- Assert(node != NULL); ./src/backend/utils/mmgr/mcxt.c- } ./src/bin/pg_archivecleanup/pg_archivecleanup.c- case 'x': ./src/bin/pg_archivecleanup/pg_archivecleanup.c: additional_ext = strdup(optarg); /* Extension to remove ./src/bin/pg_archivecleanup/pg_archivecleanup.c- * from xlogfile names */ ./src/bin/pg_archivecleanup/pg_archivecleanup.c- break; ./src/common/exec.c- if (getenv("PGLOCALEDIR") == NULL) ./src/common/exec.c- { ./src/common/exec.c- /* set for libpq to use */ ./src/common/exec.c- snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path); ./src/common/exec.c- canonicalize_path(env_path + 12); ./src/common/exec.c: putenv(strdup(env_path)); ./src/common/exec.c- } ./src/common/exec.c-#endif ./src/common/exec.c- ./src/common/exec.c- if (getenv("PGSYSCONFDIR") == NULL) ./src/common/exec.c- { ./src/common/exec.c- get_etc_path(my_exec_path, path); ./src/common/exec.c- ./src/common/exec.c- /* set for libpq to use */ ./src/common/exec.c- snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path); ./src/common/exec.c- canonicalize_path(env_path + 13); ./src/common/exec.c: putenv(strdup(env_path)); ./src/common/exec.c- } ./src/common/exec.c-} ./src/interfaces/ecpg/preproc/pgc.c- /* initialize literal buffer to a reasonable but expansible size */ ./src/interfaces/ecpg/preproc/pgc.c- if (literalbuf == NULL) ./src/interfaces/ecpg/preproc/pgc.c- { ./src/interfaces/ecpg/preproc/pgc.c- literalalloc = 1024; ./src/interfaces/ecpg/preproc/pgc.c: literalbuf = (char *) malloc(literalalloc); ./src/interfaces/ecpg/preproc/pgc.c- } ./src/interfaces/ecpg/preproc/pgc.c- if ((literallen+yleng) >= literalalloc) ./src/interfaces/ecpg/preproc/pgc.c- { ./src/interfaces/ecpg/preproc/pgc.c- do ./src/interfaces/ecpg/preproc/pgc.c- literalalloc *= 2; ./src/interfaces/ecpg/preproc/pgc.c- while ((literallen+yleng) >= literalalloc); ./src/interfaces/ecpg/preproc/pgc.c: literalbuf = (char *) realloc(literalbuf, literalalloc); ./src/interfaces/ecpg/preproc/pgc.c- } ./src/interfaces/ecpg/preproc/pgc.c- /* append new data, add trailing null */ ./src/interfaces/ecpg/preproc/pgc.c- memcpy(literalbuf+literallen, ytext, yleng); ./src/interfaces/ecpg/preproc/pgc.c- literallen += yleng; ./src/interfaces/ecpg/preproc/pgc.c- literalbuf[literallen] = '\0'; -- ./src/interfaces/ecpg/preproc/pgc.c-{ ./src/interfaces/ecpg/preproc/pgc.c- /* enlarge buffer if needed */ ./src/interfaces/ecpg/preproc/pgc.c- if ((literallen+1) >= literalalloc) ./src/interfaces/ecpg/preproc/pgc.c- { ./src/interfaces/ecpg/preproc/pgc.c- literalalloc *= 2; ./src/interfaces/ecpg/preproc/pgc.c: literalbuf = (char *) realloc(literalbuf, literalalloc); ./src/interfaces/ecpg/preproc/pgc.c- } ./src/interfaces/ecpg/preproc/pgc.c- /* append new data, add trailing null */ ./src/interfaces/ecpg/preproc/pgc.c- literalbuf[literallen] = ychar; ./src/interfaces/ecpg/preproc/pgc.c- literallen += 1; ./src/interfaces/ecpg/preproc/pgc.c- literalbuf[literallen] = '\0'; ./src/interfaces/libpq/fe-exec.c- ./src/interfaces/libpq/fe-exec.c- /* and remember the query text too, if possible */ ./src/interfaces/libpq/fe-exec.c- /* if insufficient memory, last_query just winds up NULL */ ./src/interfaces/libpq/fe-exec.c- if (conn->last_query) ./src/interfaces/libpq/fe-exec.c- free(conn->last_query); ./src/interfaces/libpq/fe-exec.c: conn->last_query = strdup(query); ./src/interfaces/libpq/fe-exec.c- ./src/interfaces/libpq/fe-exec.c- /* ./src/interfaces/libpq/fe-exec.c- * Give the data a push. In nonblock mode, don't complain if we're unable ./src/interfaces/libpq/fe-exec.c- * to send it all; PQgetResult() will do any additional flushing needed. ./src/interfaces/libpq/fe-exec.c- */ -- ./src/interfaces/libpq/fe-exec.c- ./src/interfaces/libpq/fe-exec.c- /* and remember the query text too, if possible */ ./src/interfaces/libpq/fe-exec.c- /* if insufficient memory, last_query just winds up NULL */ ./src/interfaces/libpq/fe-exec.c- if (conn->last_query) ./src/interfaces/libpq/fe-exec.c- free(conn->last_query); ./src/interfaces/libpq/fe-exec.c: conn->last_query = strdup(query); ./src/interfaces/libpq/fe-exec.c- ./src/interfaces/libpq/fe-exec.c- /* ./src/interfaces/libpq/fe-exec.c- * Give the data a push. In nonblock mode, don't complain if we're unable ./src/interfaces/libpq/fe-exec.c- * to send it all; PQgetResult() will do any additional flushing needed. ./src/interfaces/libpq/fe-exec.c- */ ./src/interfaces/libpq/fe-exec.c- /* and remember the query text too, if possible */ ./src/interfaces/libpq/fe-exec.c- /* if insufficient memory, last_query just winds up NULL */ ./src/interfaces/libpq/fe-exec.c- if (conn->last_query) ./src/interfaces/libpq/fe-exec.c- free(conn->last_query); ./src/interfaces/libpq/fe-exec.c- if (command) ./src/interfaces/libpq/fe-exec.c: conn->last_query = strdup(command); ./src/interfaces/libpq/fe-exec.c- else ./src/interfaces/libpq/fe-exec.c- conn->last_query = NULL; ./src/interfaces/libpq/fe-exec.c- ./src/interfaces/libpq/fe-exec.c- /* ./src/interfaces/libpq/fe-exec.c- * Give the data a push. In nonblock mode, don't complain if we're unable ./src/interfaces/libpq/fe-exec.c- if (!res || ./src/interfaces/libpq/fe-exec.c- (res->resultStatus != PGRES_FATAL_ERROR && ./src/interfaces/libpq/fe-exec.c- res->resultStatus != PGRES_NONFATAL_ERROR)) ./src/interfaces/libpq/fe-exec.c: return strdup(libpq_gettext("PGresult is not an error result\n")); ./src/interfaces/libpq/fe-exec.c- ./src/interfaces/libpq/fe-exec.c- ./src/interfaces/libpq/fe-exec.c- /* If insufficient memory to format the message, fail cleanly */ ./src/interfaces/libpq/fe-exec.c- if (PQExpBufferDataBroken(workBuf)) ./src/interfaces/libpq/fe-exec.c- { ./src/interfaces/libpq/fe-exec.c- termPQExpBuffer(&workBuf); ./src/interfaces/libpq/fe-exec.c: return strdup(libpq_gettext("out of memory\n")); ./src/interfaces/libpq/fe-exec.c- } ./src/interfaces/libpq/fe-exec.c- Possible resource leak: ./src/pl/tcl/pltcl.c: prodesc->user_proname = strdup(NameStr(procStruct->proname)); ./src/pl/tcl/pltcl.c: prodesc->internal_proname = strdup(internal_proname); ./src/pl/tcl/pltcl.c- if (prodesc->user_proname == NULL || prodesc->internal_proname == NULL) ./src/pl/tcl/pltcl.c- ereport(ERROR, ./src/pl/tcl/pltcl.c- (errcode(ERRCODE_OUT_OF_MEMORY), ./src/pl/tcl/pltcl.c- errmsg("out of memory"))); ./src/timezone/zic.c: directory = strdup(optarg); ./src/timezone/zic.c- else ./src/timezone/zic.c- { ./src/timezone/zic.c- fprintf(stderr, ./src/timezone/zic.c- _("%s: More than one -d option specified\n"), ./src/timezone/zic.c- progname); ./src/timezone/zic.c- return EXIT_FAILURE; ./src/timezone/zic.c- } ./src/timezone/zic.c- break; ./src/timezone/zic.c- case 'l': ./src/timezone/zic.c- if (lcltime == NULL) ./src/timezone/zic.c: lcltime = strdup(optarg); ./src/timezone/zic.c- else ./src/timezone/zic.c- { ./src/timezone/zic.c- fprintf(stderr, ./src/timezone/zic.c- _("%s: More than one -l option specified\n"), ./src/timezone/zic.c- progname); ./src/timezone/zic.c- return EXIT_FAILURE; ./src/timezone/zic.c- } ./src/timezone/zic.c- break; ./src/timezone/zic.c- case 'p': ./src/timezone/zic.c- if (psxrules == NULL) ./src/timezone/zic.c: psxrules = strdup(optarg); ./src/timezone/zic.c- else ./src/timezone/zic.c- { ./src/timezone/zic.c- fprintf(stderr, ./src/timezone/zic.c- _("%s: More than one -p option specified\n"), ./src/timezone/zic.c- progname); ./src/timezone/zic.c- return EXIT_FAILURE; ./src/timezone/zic.c- } ./src/timezone/zic.c- break; ./src/timezone/zic.c- case 'y': ./src/timezone/zic.c- if (yitcommand == NULL) ./src/timezone/zic.c: yitcommand = strdup(optarg); ./src/timezone/zic.c- else ./src/timezone/zic.c- { ./src/timezone/zic.c- fprintf(stderr, ./src/timezone/zic.c- _("%s: More than one -y option specified\n"), ./src/timezone/zic.c- progname); ./src/timezone/zic.c- return EXIT_FAILURE; ./src/timezone/zic.c- } ./src/timezone/zic.c- break; ./src/timezone/zic.c- case 'L': ./src/timezone/zic.c- if (leapsec == NULL) ./src/timezone/zic.c: leapsec = strdup(optarg);