From c2a70b7de0e15dc80d5b56d438a6d4ed47647b44 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 29 Mar 2026 09:10:57 +0100 Subject: libreboot-utils: simplify random tmpdir namegen generalise it in rand.c because this logic will be useful for other programs in the future. Signed-off-by: Leah Rowe --- util/libreboot-utils/lib/string.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'util/libreboot-utils/lib/string.c') diff --git a/util/libreboot-utils/lib/string.c b/util/libreboot-utils/lib/string.c index 6a372dcf..c3cf4519 100644 --- a/util/libreboot-utils/lib/string.c +++ b/util/libreboot-utils/lib/string.c @@ -19,6 +19,20 @@ #include "../include/common.h" +void +free_and_set_null(char **buf) +{ + if (buf == NULL) + err_exit(EFAULT, + "null ptr (to ptr for freeing) in free_and_set_null"); + + if (*buf == NULL) + return; + + free(*buf); + *buf = NULL; +} + /* safe(ish) malloc. use this and free_and_set_null() -- cgit v1.2.1