summaryrefslogtreecommitdiffstats
path: root/XUtils.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-01-05 14:47:49 +0100
committerBenBE <BenBE@geshi.org>2021-01-11 20:12:34 +0100
commit70f48f1f44bf419aac77de8664816a17122c8b29 (patch)
tree1959d394f65bf68a942e9ef4018f22a534eecfc3 /XUtils.c
parent958112c5a396815da7a731f406dbfd27bf713572 (diff)
Add wrapper function for free and strdup
Reduces code in callers and helps avoiding memory leaks.
Diffstat (limited to 'XUtils.c')
-rw-r--r--XUtils.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/XUtils.c b/XUtils.c
index fe2d8b9a..9ad8c224 100644
--- a/XUtils.c
+++ b/XUtils.c
@@ -239,6 +239,14 @@ char* xStrdup(const char* str) {
return data;
}
+void free_and_xStrdup(char** ptr, const char* str) {
+ if (*ptr && String_eq(*ptr, str))
+ return;
+
+ free(*ptr);
+ *ptr = xStrdup(str);
+}
+
char* xStrndup(const char* str, size_t len) {
char* data = strndup(str, len);
if (!data) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy