Skip to content

Commit 098c703

Browse files
committed
Remove redundant null pointer checks before pg_free()
These are especially useless because the whole point of pg_free() was to do that very check before calling free(). pg_free() could be removed altogether, but I'm keeping it here to keep the API consistent. Discussion: https://www.postgresql.org/message-id/flat/dac5d2d0-98f5-94d9-8e69-46da2413593d%40enterprisedb.com
1 parent e2bc242 commit 098c703

File tree

5 files changed

+13
-25
lines changed

5 files changed

+13
-25
lines changed

src/bin/pg_basebackup/walmethods.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ dir_close(Walfile f, WalCloseMethod method)
500500

501501
pg_free(df->pathname);
502502
pg_free(df->fullpath);
503-
if (df->temp_suffix)
504-
pg_free(df->temp_suffix);
503+
pg_free(df->temp_suffix);
505504
pg_free(df);
506505

507506
return r;

src/bin/pg_upgrade/parallel.c

+6-12
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,11 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
130130
new_arg = exec_thread_args[parallel_jobs - 1];
131131

132132
/* Can only pass one pointer into the function, so use a struct */
133-
if (new_arg->log_file)
134-
pg_free(new_arg->log_file);
133+
pg_free(new_arg->log_file);
135134
new_arg->log_file = pg_strdup(log_file);
136-
if (new_arg->opt_log_file)
137-
pg_free(new_arg->opt_log_file);
135+
pg_free(new_arg->opt_log_file);
138136
new_arg->opt_log_file = opt_log_file ? pg_strdup(opt_log_file) : NULL;
139-
if (new_arg->cmd)
140-
pg_free(new_arg->cmd);
137+
pg_free(new_arg->cmd);
141138
new_arg->cmd = pg_strdup(cmd);
142139

143140
child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_exec_prog,
@@ -243,14 +240,11 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
243240
/* Can only pass one pointer into the function, so use a struct */
244241
new_arg->old_db_arr = old_db_arr;
245242
new_arg->new_db_arr = new_db_arr;
246-
if (new_arg->old_pgdata)
247-
pg_free(new_arg->old_pgdata);
243+
pg_free(new_arg->old_pgdata);
248244
new_arg->old_pgdata = pg_strdup(old_pgdata);
249-
if (new_arg->new_pgdata)
250-
pg_free(new_arg->new_pgdata);
245+
pg_free(new_arg->new_pgdata);
251246
new_arg->new_pgdata = pg_strdup(new_pgdata);
252-
if (new_arg->old_tablespace)
253-
pg_free(new_arg->old_tablespace);
247+
pg_free(new_arg->old_tablespace);
254248
new_arg->old_tablespace = old_tablespace ? pg_strdup(old_tablespace) : NULL;
255249

256250
child = (HANDLE) _beginthreadex(NULL, 0, (void *) win32_transfer_all_new_dbs,

src/bin/pgbench/pgbench.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -5475,12 +5475,10 @@ static void
54755475
free_command(Command *command)
54765476
{
54775477
termPQExpBuffer(&command->lines);
5478-
if (command->first_line)
5479-
pg_free(command->first_line);
5478+
pg_free(command->first_line);
54805479
for (int i = 0; i < command->argc; i++)
54815480
pg_free(command->argv[i]);
5482-
if (command->varprefix)
5483-
pg_free(command->varprefix);
5481+
pg_free(command->varprefix);
54845482

54855483
/*
54865484
* It should also free expr recursively, but this is currently not needed
@@ -6637,8 +6635,7 @@ main(int argc, char **argv)
66376635
is_init_mode = true;
66386636
break;
66396637
case 'I':
6640-
if (initialize_steps)
6641-
pg_free(initialize_steps);
6638+
pg_free(initialize_steps);
66426639
initialize_steps = pg_strdup(optarg);
66436640
checkInitSteps(initialize_steps);
66446641
initialization_option_set = true;

src/bin/psql/command.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -3492,8 +3492,7 @@ do_connect(enum trivalue reuse_previous_specification,
34923492
} /* end retry loop */
34933493

34943494
/* Release locally allocated data, whether we succeeded or not */
3495-
if (password)
3496-
pg_free(password);
3495+
pg_free(password);
34973496
if (cinfo)
34983497
PQconninfoFree(cinfo);
34993498

src/bin/psql/variables.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ SetVariable(VariableSpace space, const char *name, const char *value)
255255

256256
if (confirmed)
257257
{
258-
if (current->value)
259-
pg_free(current->value);
258+
pg_free(current->value);
260259
current->value = new_value;
261260

262261
/*
@@ -272,7 +271,7 @@ SetVariable(VariableSpace space, const char *name, const char *value)
272271
free(current);
273272
}
274273
}
275-
else if (new_value)
274+
else
276275
pg_free(new_value); /* current->value is left unchanged */
277276

278277
return confirmed;

0 commit comments

Comments
 (0)