]> err.no Git - systemd/commitdiff
coverity: fix a couple of bugs found by coverity
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Sep 2011 23:43:28 +0000 (01:43 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Sep 2011 23:45:34 +0000 (01:45 +0200)
15 files changed:
src/binfmt.c
src/conf-parser.c
src/install.c
src/load-fragment.c
src/localed.c
src/logind-dbus.c
src/modules-load.c
src/path.c
src/sd-login.c
src/service.c
src/socket.c
src/strv.c
src/systemctl.c
src/timedated.c
src/util.c

index 552d8cc227ec5131c1071573560197782e1b6181..e8d65243918453276cc2165076583f9d4b387d12 100644 (file)
@@ -33,7 +33,7 @@
 #include "util.h"
 
 static int delete_rule(const char *rule) {
-        char *x, *fn, *e;
+        char *x, *fn = NULL, *e;
         int r;
 
         assert(rule[0]);
index 3bb430e375183499889243ee9ef14169e141123a..a71dcd0d8fb8c87460ea24f81b244334ce740519 100644 (file)
@@ -314,7 +314,7 @@ int config_parse(
                                 continuation = c;
                         else {
                                 continuation = strdup(l);
-                                if (!c) {
+                                if (!continuation) {
                                         r = -ENOMEM;
                                         goto finish;
                                 }
index 7443973502e6177ad0794304be3bfe716d7eb5b1..53dd26fd7f2f75998940fd49ed7239958802b83f 100644 (file)
@@ -479,7 +479,6 @@ static int find_symlinks_fd(
                                 t = path_make_absolute(name, config_path);
                                 if (!t) {
                                         free(p);
-                                        free(dest);
                                         r = -ENOMEM;
                                         break;
                                 }
index c7d2da34b48697f37ed73c0eb9e7f367b4f586e6..12079c640fdefbeebca6bceb9752ab0494ae8968 100644 (file)
@@ -554,6 +554,7 @@ int config_parse_exec(
                 if (!n[0]) {
                         log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue);
                         strv_free(n);
+                        free(path);
                         return 0;
                 }
 
index f652110db49d3dec46ed5123495e7db6e8661b2d..fbb5a41d1a1232312affa6d473d69e5fbf4b924e 100644 (file)
@@ -215,6 +215,7 @@ static int write_data(void) {
         }
 
         if (strv_isempty(l)) {
+                strv_free(l);
 
                 if (unlink("/etc/locale.conf") < 0)
                         return errno == ENOENT ? 0 : -errno;
@@ -459,6 +460,8 @@ static DBusHandlerResult locale_message_handler(
                                 }
                         }
 
+                        strv_free(l);
+
                         for (p = 0; p < _PROP_MAX; p++) {
                                 if (passed[p])
                                         continue;
index b8f7d6718ba09de50d2d0f0f19130ad96890da34..b33a096f3c1076c56b3793615dcbf130cc34223e 100644 (file)
@@ -381,6 +381,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
                 session = hashmap_get(m->sessions, id);
 
                 if (session) {
+                        free(id);
 
                         fifo_fd = session_create_fifo(session);
                         if (fifo_fd < 0) {
@@ -421,6 +422,9 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
                         close_nointr_nofail(fifo_fd);
                         *_reply = reply;
 
+                        strv_free(controllers);
+                        strv_free(reset_controllers);
+
                         return 0;
                 }
 
index 17b5e0bf80d5b3213d39eeb6ea1941509098287d..8dd98f73d82482a30bd9945d8cab97ebf43e61d4 100644 (file)
@@ -77,7 +77,6 @@ int main(int argc, char *argv[]) {
                                 continue;
 
                         log_error("Failed to open %s: %m", *fn);
-                        free(fn);
                         r = EXIT_FAILURE;
                         continue;
                 }
index 1d4aa2174a06fa20246a6f8e2764045d06448cd5..f15c9214efb35c73fd5cdea904dc802d5fc783cd 100644 (file)
@@ -563,7 +563,7 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
         assert(l > 0);
 
         if (!(buf = malloc(l))) {
-                log_error("Failed to allocate buffer: %s", strerror(-ENOMEM));
+                log_error("Failed to allocate buffer: %s", strerror(ENOMEM));
                 goto fail;
         }
 
index 2489d78c603dba842113eda63d8ee663eb0100ce..b670d18266a7a85ec557e8efa698be158755c411 100644 (file)
@@ -499,6 +499,7 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
                         if (!k) {
                                 free(t);
                                 free(b);
+                                strv_free(a);
                                 return -ENOMEM;
                         }
 
@@ -574,6 +575,9 @@ _public_ int sd_get_uids(uid_t **users) {
         uid_t *l = NULL;
 
         d = opendir("/run/systemd/users/");
+        if (!d)
+                return -errno;
+
         for (;;) {
                 struct dirent buffer, *de;
                 int k;
index 2b45ecb71547f5d3d21d328c2b7843f76253a9b9..2ae8785ac4e484f13fe21d8fa25beac85752a1b4 100644 (file)
@@ -3115,7 +3115,7 @@ static int service_enumerate(Manager *m) {
 
                                 free(fpath);
                                 fpath = join(path, "/", de->d_name, NULL);
-                                if (!path) {
+                                if (!fpath) {
                                         r = -ENOMEM;
                                         goto finish;
                                 }
index 572e622011bfc02678925ef06826d5bbdce03fd9..a1b451eba0f9bd640f35fdeb6c3b7a4a148c667b 100644 (file)
@@ -844,7 +844,7 @@ static int mq_address_create(
         fd = mq_open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_CREAT, mq_mode, attr);
         umask(old_mask);
 
-        if (fd < 0 && errno != EEXIST) {
+        if (fd < 0) {
                 r = -errno;
                 goto fail;
         }
index 92851b223375516b5144f52afcc2ca4b471333fd..640ae3f0a3dacddd967834fb1fa5320cd5a58cb6 100644 (file)
@@ -201,12 +201,19 @@ char **strv_merge_concat(char **a, char **b, const char *suffix) {
         if (!(r = new(char*, strv_length(a)+strv_length(b)+1)))
                 return NULL;
 
-        for (k = r; *a; k++, a++)
-                if (!(*k = strdup(*a)))
-                        goto fail;
-        for (; *b; k++, b++)
-                if (!(*k = strappend(*b, suffix)))
+        k = r;
+        if (a)
+                for (; *a; k++, a++) {
+                        *k = strdup(*a);
+                        if (!*k)
+                                goto fail;
+                }
+
+        for (; *b; k++, b++) {
+                *k = strappend(*b, suffix);
+                if (!*k)
                         goto fail;
+        }
 
         *k = NULL;
         return r;
index 7caeb6dd91bd81a54fb6a7b486f2d6b55020133d..e85a2fd44c249337bba3e08bfc7a6c8dbd426156 100644 (file)
@@ -608,6 +608,7 @@ static int list_unit_files(DBusConnection *bus, char **args) {
 
                 r = unit_file_get_list(arg_scope, arg_root, h);
                 if (r < 0) {
+                        unit_file_list_free(h);
                         log_error("Failed to get unit file list: %s", strerror(-r));
                         return r;
                 }
index 66e50a68687e884f9e3fb1809430f009e78dbcf7..f6fe2d83b646429c5ca04c45d137664a00d9eea9 100644 (file)
@@ -246,7 +246,7 @@ static int write_data_local_rtc(void) {
 
                 p++;
                 e = strchr(p, '\n');
-                if (!p) {
+                if (!e) {
                         free(s);
                         return -EIO;
                 }
index 6033aa05b271b4f55f361d31d576ba13c979de76..6a9fffbf3df88e9531bee37390987b7a29f07e44 100644 (file)
@@ -5529,6 +5529,9 @@ int get_files_in_directory(const char *path, char ***list) {
          * number */
 
         d = opendir(path);
+        if (!d)
+                return -errno;
+
         for (;;) {
                 struct dirent buffer, *de;
                 int k;
@@ -5629,6 +5632,8 @@ char *join(const char *x, ...) {
 
                         p = stpcpy(p, t);
                 }
+
+                va_end(ap);
         } else
                 r[0] = 0;