pg_malloc, to avoid linker failures on same platforms.
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.110 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.111 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
#include "command.h"
* backslash command ended */
psql_assert(line);
- my_line = xstrdup(line);
+ my_line = pg_strdup(line);
/*
* Find the first whitespace. line[blank_loc] will now be the
* end.
*/
if (options_string)
- string = string_cpy = xstrdup(options_string);
+ string = string_cpy = pg_strdup(options_string);
else
string = string_cpy = NULL;
else
{
expand_tilde(&fname);
- pset.gfname = xstrdup(fname);
+ pset.gfname = pg_strdup(fname);
}
free(fname);
status = CMD_SEND;
char *opt;
opt = scan_option(&string, OT_NORMAL, NULL, false);
- newval = xstrdup(opt ? opt : "");
+ newval = pg_strdup(opt ? opt : "");
free(opt);
while ((opt = scan_option(&string, OT_NORMAL, NULL, false)))
}
else
{
- return_val = xstrdup("");
+ return_val = pg_strdup("");
termPQExpBuffer(&output);
}
save_char = options_string[pos + token_end + 1];
options_string[pos + token_end + 1] = '\0';
value = GetVariable(pset.vars, options_string + pos + 1);
- return_val = xstrdup(value ? value : "");
+ return_val = pg_strdup(value ? value : "");
options_string[pos + token_end + 1] = save_char;
*string = &options_string[pos + token_end + 1];
/* XXX should we set *quote to ':' here? */
if (type == OT_FILEPIPE)
{
*string += strlen(*string);
- return xstrdup(options_string + pos);
+ return pg_strdup(options_string + pos);
}
/* fallthrough for other option types */
/* Copy the option */
token_len = cp - &options_string[pos];
- return_val = xmalloc(token_len + 1);
+ return_val = pg_malloc(token_len + 1);
memcpy(return_val, &options_string[pos], token_len);
return_val[token_len] = '\0';
length = Min(len, strlen(source)) + 1;
- tmp = destination = xmalloc(length);
+ tmp = destination = pg_malloc(length);
for (p = source; p - source < (int) len && *p; p += PQmblen(p, pset.encoding))
{
if (!editorName)
editorName = DEFAULT_EDITOR;
- sys = xmalloc(strlen(editorName) + strlen(fname) + 10 + 1);
+ sys = pg_malloc(strlen(editorName) + strlen(fname) + 10 + 1);
sprintf(sys,
#ifndef WIN32
"exec "
if (value)
{
free(popt->nullPrint);
- popt->nullPrint = xstrdup(value);
+ popt->nullPrint = pg_strdup(value);
}
if (!quiet)
printf(gettext("Null display is \"%s\".\n"), popt->nullPrint ? popt->nullPrint : "");
if (value)
{
free(popt->topt.fieldSep);
- popt->topt.fieldSep = xstrdup(value);
+ popt->topt.fieldSep = pg_strdup(value);
}
if (!quiet)
printf(gettext("Field separator is \"%s\".\n"), popt->topt.fieldSep);
if (value)
{
free(popt->topt.recordSep);
- popt->topt.recordSep = xstrdup(value);
+ popt->topt.recordSep = pg_strdup(value);
}
if (!quiet)
{
if (!value)
popt->title = NULL;
else
- popt->title = xstrdup(value);
+ popt->title = pg_strdup(value);
if (!quiet)
{
if (!value)
popt->topt.tableAttr = NULL;
else
- popt->topt.tableAttr = xstrdup(value);
+ popt->topt.tableAttr = pg_strdup(value);
if (!quiet)
{
if (shellName == NULL)
shellName = DEFAULT_SHELL;
- sys = xmalloc(strlen(shellName) + 16);
+ sys = pg_malloc(strlen(shellName) + 16);
sprintf(sys,
#ifndef WIN32
"exec "
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.81 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.82 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
#include "common.h"
* "Safe" wrapper around strdup()
*/
char *
-xstrdup(const char *string)
+pg_strdup(const char *string)
{
char *tmp;
}
void *
-xmalloc(size_t size)
+pg_malloc(size_t size)
{
void *tmp;
}
void *
-xmalloc_zero(size_t size)
+pg_malloc_zero(size_t size)
{
void *tmp;
- tmp = xmalloc(size);
+ tmp = pg_malloc(size);
memset(tmp, 0, size);
return tmp;
}
void *
-xcalloc(size_t nmemb, size_t size)
+pg_calloc(size_t nmemb, size_t size)
{
void *tmp;
return tmp;
}
-
/*
* setQFout
* -- handler for -o command line option and \o command
{
char *newfn;
- newfn = xmalloc(strlen(home) + strlen(p) + 1);
+ newfn = pg_malloc(strlen(home) + strlen(p) + 1);
strcpy(newfn, home);
strcat(newfn, p);
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.33 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.34 2004/01/25 03:07:22 neilc Exp $
*/
#ifndef COMMON_H
#define COMMON_H
* out-of-memory condition occurs, these functions will bail out
* safely; therefore, their return value is guaranteed to be non-NULL.
*/
-extern char *xstrdup(const char *string);
-extern void *xmalloc(size_t size);
-extern void *xmalloc_zero(size_t size);
-extern void *xcalloc(size_t nmemb, size_t size);
+extern char *pg_strdup(const char *string);
+extern void *pg_malloc(size_t size);
+extern void *pg_malloc_zero(size_t size);
+extern void *pg_calloc(size_t nmemb, size_t size);
extern bool setQFout(const char *fname);
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.38 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.39 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
#include "copy.h"
{
char *newvar;
- newvar = xmalloc(strlen(*var) + strlen(more) + 1);
+ newvar = pg_malloc(strlen(*var) + strlen(more) + 1);
strcpy(newvar, *var);
strcat(newvar, more);
free(*var);
const char *whitespace = " \t\n\r";
if (args)
- line = xstrdup(args);
+ line = pg_strdup(args);
else
{
psql_error("\\copy: arguments required\n");
return NULL;
}
- result = xcalloc(1, sizeof(struct copy_options));
+ result = pg_calloc(1, sizeof(struct copy_options));
token = strtokx(line, whitespace, ".,()", "\"",
0, false, pset.encoding);
}
#endif
- result->table = xstrdup(token);
+ result->table = pg_strdup(token);
token = strtokx(NULL, whitespace, ".,()", "\"",
0, false, pset.encoding);
if (token[0] == '(')
{
/* handle parenthesized column list */
- result->column_list = xstrdup(token);
+ result->column_list = pg_strdup(token);
for (;;)
{
token = strtokx(NULL, whitespace, ".,()", "\"",
else
{
result->in_dash = false;
- result->file = xstrdup(token);
+ result->file = pg_strdup(token);
expand_tilde(&result->file);
}
'\\', false, pset.encoding);
if (!token)
goto error;
- result->delim = xstrdup(token);
+ result->delim = pg_strdup(token);
token = strtokx(NULL, whitespace, NULL, NULL,
0, false, pset.encoding);
}
token = strtokx(NULL, whitespace, NULL, "'",
'\\', false, pset.encoding);
if (token)
- result->delim = xstrdup(token);
+ result->delim = pg_strdup(token);
else
goto error;
}
token = strtokx(NULL, whitespace, NULL, "'",
'\\', false, pset.encoding);
if (token)
- result->null = xstrdup(token);
+ result->null = pg_strdup(token);
else
goto error;
}
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.93 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.94 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
#include "describe.h"
const char *schemavar, const char *namevar,
const char *altnamevar, const char *visibilityrule);
-static void *
-xmalloczero(size_t size)
-{
- void *tmp;
-
- tmp = xmalloc(size);
- memset(tmp, 0, size);
- return tmp;
-}
-
-
/*----------------
* Handlers for various slash commands displaying some sort of list
* of things in the database.
goto error_return;
if (PQntuples(result) > 0)
- view_def = xstrdup(PQgetvalue(result, 0, 0));
+ view_def = pg_strdup(PQgetvalue(result, 0, 0));
PQclear(result);
}
/* Generate table cells to be printed */
/* note: initialize all cells[] to NULL in case of error exit */
- cells = xmalloczero((numrows * cols + 1) * sizeof(*cells));
+ cells = pg_malloc_zero((numrows * cols + 1) * sizeof(*cells));
for (i = 0; i < numrows; i++)
{
}
#ifdef WIN32
- cells[i * cols + 2] = xstrdup(mbvalidate(tmpbuf.data, myopt.encoding));
+ cells[i * cols + 2] = pg_strdup(mbvalidate(tmpbuf.data, myopt.encoding));
#else
- cells[i * cols + 2] = xstrdup(tmpbuf.data);
+ cells[i * cols + 2] = pg_strdup(tmpbuf.data);
#endif
}
if (strlen(indpred))
appendPQExpBuffer(&tmpbuf, _(", predicate (%s)"), indpred);
- footers = xmalloczero(2 * sizeof(*footers));
- footers[0] = xstrdup(tmpbuf.data);
+ footers = pg_malloc_zero(2 * sizeof(*footers));
+ footers[0] = pg_strdup(tmpbuf.data);
footers[1] = NULL;
}
}
/* Footer information about a view */
- footers = xmalloczero((rule_count + 3) * sizeof(*footers));
- footers[count_footers] = xmalloc(64 + strlen(view_def));
+ footers = pg_malloc_zero((rule_count + 3) * sizeof(*footers));
+ footers[count_footers] = pg_malloc(64 + strlen(view_def));
snprintf(footers[count_footers], 64 + strlen(view_def),
_("View definition:\n%s"), view_def);
count_footers++;
if (rule_count > 0)
{
printfPQExpBuffer(&buf, _("Rules:"));
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
for (i = 0; i < rule_count; i++)
{
const char *ruledef;
printfPQExpBuffer(&buf, " %s", ruledef);
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
}
PQclear(result);
}
else
inherits_count = PQntuples(result6);
- footers = xmalloczero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inherits_count + 6)
- * sizeof(*footers));
+ footers = pg_malloc_zero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inherits_count + 6)
+ * sizeof(*footers));
/* print indexes */
if (index_count > 0)
{
printfPQExpBuffer(&buf, _("Indexes:"));
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
for (i = 0; i < index_count; i++)
{
const char *indexdef;
appendPQExpBuffer(&buf, " %s", indexdef);
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
}
}
if (check_count > 0)
{
printfPQExpBuffer(&buf, _("Check constraints:"));
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
for (i = 0; i < check_count; i++)
{
printfPQExpBuffer(&buf, _(" \"%s\" %s"),
PQgetvalue(result2, i, 1),
PQgetvalue(result2, i, 0));
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
}
}
if (foreignkey_count > 0)
{
printfPQExpBuffer(&buf, _("Foreign-key constraints:"));
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
for (i = 0; i < foreignkey_count; i++)
{
printfPQExpBuffer(&buf, _(" \"%s\" %s"),
PQgetvalue(result5, i, 0),
PQgetvalue(result5, i, 1));
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
}
}
if (rule_count > 0)
{
printfPQExpBuffer(&buf, _("Rules:"));
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
for (i = 0; i < rule_count; i++)
{
const char *ruledef;
printfPQExpBuffer(&buf, " %s", ruledef);
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
}
}
if (trigger_count > 0)
{
printfPQExpBuffer(&buf, _("Triggers:"));
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
for (i = 0; i < trigger_count; i++)
{
const char *tgdef;
printfPQExpBuffer(&buf, " %s", tgdef);
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
}
}
if (i < inherits_count - 1)
appendPQExpBuffer(&buf, ",");
- footers[count_footers++] = xstrdup(buf.data);
+ footers[count_footers++] = pg_strdup(buf.data);
}
/* end of list marker */
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.33 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.34 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
#include "input.h"
else
{
free(prev_hist);
- prev_hist = xstrdup(s);
+ prev_hist = pg_strdup(s);
add_history(s);
}
}
{
char *psql_history;
- psql_history = xmalloc(strlen(home) + 1 +
- strlen(PSQLHISTORY) + 1);
+ psql_history = pg_malloc(strlen(home) + 1 +
+ strlen(PSQLHISTORY) + 1);
sprintf(psql_history, "%s/%s", home, PSQLHISTORY);
read_history(psql_history);
free(psql_history);
char *psql_history;
int hist_size;
- psql_history = xmalloc(strlen(home) + 1 +
- strlen(PSQLHISTORY) + 1);
+ psql_history = pg_malloc(strlen(home) + 1 +
+ strlen(PSQLHISTORY) + 1);
hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true);
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.60 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.61 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
#include "mainloop.h"
* just returned from editing the line? then just copy to the
* input buffer
*/
- line = xstrdup(query_buf->data);
+ line = pg_strdup(query_buf->data);
resetPQExpBuffer(query_buf);
/* reset parsing state since we are rescanning whole line */
in_xcomment = 0;
/* It is a variable, perform substitution */
out_length = strlen(value);
- new = xmalloc(len + out_length - in_length + 1);
+ new = pg_malloc(len + out_length - in_length + 1);
sprintf(new, "%.*s%s%s", i, line, value,
&line[i + thislen + in_length]);
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.33 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.34 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
#include "prompt.h"
case '`':
{
FILE *fd = NULL;
- char *file = xstrdup(p + 1);
+ char *file = pg_strdup(p + 1);
int cmdend;
cmdend = strcspn(file, "`");
const char *val;
int nameend;
- name = xstrdup(p + 1);
+ name = pg_strdup(p + 1);
nameend = strcspn(name, ":");
name[nameend] = '\0';
val = GetVariable(pset.vars, name);
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.82 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.83 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
parse_psql_options(argc, argv, &options);
if (!pset.popt.topt.fieldSep)
- pset.popt.topt.fieldSep = xstrdup(DEFAULT_FIELD_SEP);
+ pset.popt.topt.fieldSep = pg_strdup(DEFAULT_FIELD_SEP);
if (!pset.popt.topt.recordSep)
- pset.popt.topt.recordSep = xstrdup(DEFAULT_RECORD_SEP);
+ pset.popt.topt.recordSep = pg_strdup(DEFAULT_RECORD_SEP);
if (options.username)
{
if (strcmp(options.username, "\001") == 0)
username = simple_prompt("User name: ", 100, true);
else
- username = xstrdup(options.username);
+ username = pg_strdup(options.username);
}
if (pset.getPassword)
options->action_string = optarg;
break;
case 'F':
- pset.popt.topt.fieldSep = xstrdup(optarg);
+ pset.popt.topt.fieldSep = pg_strdup(optarg);
break;
case 'h':
options->host = optarg;
char *equal_loc;
bool result;
- value = xstrdup(optarg);
+ value = pg_strdup(optarg);
equal_loc = strchr(value, '=');
if (!equal_loc)
result = do_pset(value, NULL, &pset.popt, true);
SetVariableBool(pset.vars, "QUIET");
break;
case 'R':
- pset.popt.topt.recordSep = xstrdup(optarg);
+ pset.popt.topt.recordSep = pg_strdup(optarg);
break;
case 's':
SetVariableBool(pset.vars, "SINGLESTEP");
pset.popt.topt.tuples_only = true;
break;
case 'T':
- pset.popt.topt.tableAttr = xstrdup(optarg);
+ pset.popt.topt.tableAttr = pg_strdup(optarg);
break;
case 'u':
pset.getPassword = true;
char *value;
char *equal_loc;
- value = xstrdup(optarg);
+ value = pg_strdup(optarg);
equal_loc = strchr(value, '=');
if (!equal_loc)
{
if (home)
{
- psqlrc = xmalloc(strlen(home) + 1 + strlen(PSQLRC) + 1 +
- strlen(PG_VERSION) + 1);
+ psqlrc = pg_malloc(strlen(home) + 1 + strlen(PSQLRC) + 1 +
+ strlen(PG_VERSION) + 1);
sprintf(psqlrc, "%s/%s-%s", home, PSQLRC, PG_VERSION);
if (access(psqlrc, R_OK) == 0)
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/stringutils.c,v 1.37 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/stringutils.c,v 1.38 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
* tokens. 2X the space is a gross overestimate, but it's
* unlikely that this code will be used on huge strings anyway.
*/
- storage = xmalloc(2 * strlen(s) + 1);
+ storage = pg_malloc(2 * strlen(s) + 1);
strcpy(storage, s);
string = storage;
}
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.99 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.100 2004/01/25 03:07:22 neilc Exp $
*/
/*----------------------------------------------------------------------
/* find something that matches */
while ((name = words_after_create[list_index++].name))
if (strncasecmp(name, text, string_length) == 0)
- return xstrdup(name);
+ return pg_strdup(name);
/* if nothing matches, return NULL */
return NULL;
/* Set up suitably-escaped copies of textual inputs */
if (text)
{
- e_text = xmalloc(strlen(text) * 2 + 1);
+ e_text = pg_malloc(strlen(text) * 2 + 1);
PQescapeString(e_text, text, strlen(text));
}
else
size_t charp_len;
charp_len = strlen(completion_info_charp);
- e_info_charp = xmalloc(charp_len * 2 + 1);
+ e_info_charp = pg_malloc(charp_len * 2 + 1);
PQescapeString(e_info_charp, completion_info_charp,
charp_len);
}
while (list_index < PQntuples(result) &&
(item = PQgetvalue(result, list_index++, 0)))
if (strncasecmp(text, item, string_length) == 0)
- return xstrdup(item);
+ return pg_strdup(item);
}
/* If nothing matches, free the db structure and return null */
if (casesensitive && strncmp(text, item, string_length) == 0)
{
matches++;
- return xstrdup(item);
+ return pg_strdup(item);
}
/* Second pass is case insensitive, don't bother counting matches */
if (!casesensitive && strncasecmp(text, item, string_length) == 0)
- return xstrdup(item);
+ return pg_strdup(item);
}
/*
psql_assert(completion_charp);
if (state == 0)
- return xstrdup(completion_charp);
+ return pg_strdup(completion_charp);
else
return NULL;
}
}
/* make a copy */
- s = xmalloc(end - start + 2);
+ s = pg_malloc(end - start + 2);
strncpy(s, &rl_line_buffer[start], end - start + 1);
s[end - start + 1] = '\0';
(void) quote_pointer; /* not used */
length = strlen(text) +(match_type == SINGLE_MATCH ? 3 : 2);
- s = xmalloc(length);
+ s = pg_malloc(length);
s[0] = '\'';
strcpy(s + 1, text);
if (match_type == SINGLE_MATCH)
size_t length;
if (!quote_char)
- return xstrdup(text);
+ return pg_strdup(text);
length = strlen(text);
- s = xmalloc(length - 2 + 1);
+ s = pg_malloc(length - 2 + 1);
strncpy(s, text +1, length - 2);
s[length] = '\0';
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.16 2004/01/24 19:38:49 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.17 2004/01/25 03:07:22 neilc Exp $
*/
#include "postgres_fe.h"
#include "common.h"
{
struct _variable *ptr;
- ptr = xcalloc(1, sizeof *ptr);
- ptr->name = xstrdup("@");
- ptr->value = xstrdup("");
+ ptr = pg_calloc(1, sizeof *ptr);
+ ptr->name = pg_strdup("@");
+ ptr->value = pg_strdup("");
return ptr;
}
if (strcmp(current->name, name) == 0)
{
free(current->value);
- current->value = xstrdup(value);
+ current->value = pg_strdup(value);
return true;
}
}
- previous->next = xcalloc(1, sizeof *(previous->next));
- previous->next->name = xstrdup(name);
- previous->next->value = xstrdup(value);
+ previous->next = pg_calloc(1, sizeof *(previous->next));
+ previous->next->name = pg_strdup(name);
+ previous->next->value = pg_strdup(value);
return true;
}