chiark / gitweb /
execute,util: fix two small memory leaks
[elogind.git] / src / util.c
index 21afdceb8cc4cf666de6d36318c1ea30be175de7..67a75c5702fa9f0490df241ad5eefb5e9b26f966 100644 (file)
@@ -3090,6 +3090,9 @@ void status_welcome(void) {
         status_printf("Welcome to \x1B[%sm%s\x1B[0m!\n",
                       const_color ? const_color : ansi_color,
                       const_pretty ? const_pretty : pretty_name);
+
+        free(ansi_color);
+        free(pretty_name);
 }
 
 char *replace_env(const char *format, char **env) {
@@ -3436,7 +3439,18 @@ bool null_or_empty(struct stat *st) {
 }
 
 DIR *xopendirat(int fd, const char *name, int flags) {
-        return fdopendir(openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags));
+        int nfd;
+        DIR *d;
+
+        if ((nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags)) < 0)
+                return NULL;
+
+        if (!(d = fdopendir(nfd))) {
+                close_nointr_nofail(nfd);
+                return NULL;
+        }
+
+        return d;
 }
 
 int signal_from_string_try_harder(const char *s) {