]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: drop alloca() in loop
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Jun 2019 21:29:19 +0000 (06:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Jun 2019 21:29:19 +0000 (06:29 +0900)
src/delta/delta.c
src/getty-generator/getty-generator.c
src/journal/journalctl.c
src/journal/journald-audit.c
src/libsystemd/sd-device/sd-device.c
src/locale/keymap-util.c

index 63baa747949e590c8c55bf62a59bea834a4ad7bd..08d8867431d6ffacf0b00f58e2ffeef4175295d1 100644 (file)
@@ -371,7 +371,7 @@ static int enumerate_dir(
         return 0;
 }
 
-static bool should_skip_path(const char *prefix, const char *suffix) {
+static int should_skip_path(const char *prefix, const char *suffix) {
 #if HAVE_SPLIT_USR
         _cleanup_free_ char *target = NULL;
         const char *p;
@@ -383,10 +383,16 @@ static bool should_skip_path(const char *prefix, const char *suffix) {
                 return false;
 
         NULSTR_FOREACH(p, prefixes) {
+                _cleanup_free_ char *tmp = NULL;
+
                 if (path_startswith(dirname, p))
                         continue;
 
-                if (path_equal(target, strjoina(p, "/", suffix))) {
+                tmp = path_join(p, suffix);
+                if (!tmp)
+                        return -ENOMEM;
+
+                if (path_equal(target, tmp)) {
                         log_debug("%s redirects to %s, skipping.", dirname, target);
                         return true;
                 }
@@ -423,7 +429,7 @@ static int process_suffix(const char *suffix, const char *onlyprefix) {
         NULSTR_FOREACH(p, prefixes) {
                 _cleanup_free_ char *t = NULL;
 
-                if (should_skip_path(p, suffix))
+                if (should_skip_path(p, suffix) > 0)
                         continue;
 
                 t = strjoin(p, "/", suffix);
index 35501b61f59d43df8c8997384044d47ddfb0c8f8..8610ab67058462e3c1dba9a757c1bf302d177155 100644 (file)
@@ -189,9 +189,11 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
                        "sclp_line0",
                        "ttysclp0",
                        "3270!tty1") {
-                const char *p;
+                _cleanup_free_ char *p = NULL;
 
-                p = strjoina("/sys/class/tty/", j);
+                p = path_join("/sys/class/tty", j);
+                if (!p)
+                        return -ENOMEM;
                 if (access(p, F_OK) < 0)
                         continue;
 
index 3d053c59f008520264bb50c231cb276ca49c2c5c..d10bced3b7a60a3b8e7423ac4216b6b866f98154 100644 (file)
@@ -1678,9 +1678,11 @@ static int add_syslog_identifier(sd_journal *j) {
         assert(j);
 
         STRV_FOREACH(i, arg_syslog_identifier) {
-                char *u;
+                _cleanup_free_ char *u = NULL;
 
-                u = strjoina("SYSLOG_IDENTIFIER=", *i);
+                u = strjoin("SYSLOG_IDENTIFIER=", *i);
+                if (!u)
+                        return -ENOMEM;
                 r = sd_journal_add_match(j, u, 0);
                 if (r < 0)
                         return r;
index 71d9282ed52133c5510b09c06e2089fede07006c..fae9138ecb23b4360bc3e2efe6c53927a9f0e40b 100644 (file)
@@ -264,8 +264,8 @@ static int map_all_fields(
                 if (handle_msg) {
                         v = startswith(p, "msg='");
                         if (v) {
+                                _cleanup_free_ char *c = NULL;
                                 const char *e;
-                                char *c;
 
                                 /* Userspace message. It's enclosed in
                                    simple quotation marks, is not
@@ -279,7 +279,10 @@ static int map_all_fields(
                                 if (!e)
                                         return 0; /* don't continue splitting up if the final quotation mark is missing */
 
-                                c = strndupa(v, e - v);
+                                c = strndup(v, e - v);
+                                if (!c)
+                                        return -ENOMEM;
+
                                 return map_all_fields(c, map_fields_userspace, "AUDIT_FIELD_", false, iov, n_iov_allocated, n_iov);
                         }
                 }
index c2315c03fe6d803403e0a0c747fa59c3270c822a..b1572981b175474485b07d0d7dbc78f819ecae79 100644 (file)
@@ -1600,14 +1600,16 @@ static int device_sysattrs_read_all(sd_device *device) {
                 return r;
 
         FOREACH_DIRENT_ALL(dent, dir, return -errno) {
-                char *path;
+                _cleanup_free_ char *path = NULL;
                 struct stat statbuf;
 
                 /* only handle symlinks and regular files */
                 if (!IN_SET(dent->d_type, DT_LNK, DT_REG))
                         continue;
 
-                path = strjoina(syspath, "/", dent->d_name);
+                path = path_join(syspath, dent->d_name);
+                if (!path)
+                        return -ENOMEM;
 
                 if (lstat(path, &statbuf) != 0)
                         continue;
index e238e5a124c2df6f5778a5186c397e12a4b440a6..c7dcd8ad38b644e2ab7bac647059b64debaf292c 100644 (file)
@@ -648,11 +648,11 @@ int find_legacy_keymap(Context *c, char **ret) {
                         if (startswith_comma(c->x11_layout, a[1]))
                                 matching = 5;
                         else  {
-                                char *x;
+                                _cleanup_free_ char *x = NULL;
 
                                 /* If that didn't work, strip off the
                                  * other layouts from the entry, too */
-                                x = strndupa(a[1], strcspn(a[1], ","));
+                                x = strndup(a[1], strcspn(a[1], ","));
                                 if (startswith_comma(c->x11_layout, x))
                                         matching = 1;
                         }