summaryrefslogtreecommitdiff
path: root/libpkgconf/argvsplit.c
diff options
context:
space:
mode:
Diffstat (limited to 'libpkgconf/argvsplit.c')
-rw-r--r--libpkgconf/argvsplit.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/libpkgconf/argvsplit.c b/libpkgconf/argvsplit.c
index 1ff221ac63f8..8c5dac2917df 100644
--- a/libpkgconf/argvsplit.c
+++ b/libpkgconf/argvsplit.c
@@ -2,6 +2,8 @@
* argvsplit.c
* argv_split() routine
*
+ * SPDX-License-Identifier: pkgconf
+ *
* Copyright (c) 2012, 2017 pkgconf authors (see AUTHORS).
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -39,6 +41,9 @@
void
pkgconf_argv_free(char **argv)
{
+ if (argv == NULL)
+ return;
+
free(argv[0]);
free(argv);
}
@@ -118,8 +123,19 @@ pkgconf_argv_split(const char *src, int *argc, char ***argv)
if (argc_count == argv_size)
{
+ char **new_argv;
+
argv_size += 5;
- *argv = realloc(*argv, sizeof(void *) * argv_size);
+ new_argv = pkgconf_reallocarray(*argv, argv_size, sizeof(void *));
+ if (new_argv == NULL)
+ {
+ free(*argv);
+ free(buf);
+ *argv = NULL;
+ return -1;
+ }
+
+ *argv = new_argv;
}
(*argv)[argc_count] = dst_iter;
@@ -148,6 +164,7 @@ pkgconf_argv_split(const char *src, int *argc, char ***argv)
{
free(*argv);
free(buf);
+ *argv = NULL;
return -1;
}