diff options
author | Colin Cross <ccross@android.com> | 2016-01-29 16:21:31 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2016-02-02 13:55:42 -0800 |
commit | 7a106f7c1220fc749ca137675ac7b4c915418f47 (patch) | |
tree | 446dd85365fb7947247c4bf356d5db6cce8c12ee /liblog | |
parent | a9352202dd52a404199fbdca160d9d2d0992cf63 (diff) | |
download | core-7a106f7c1220fc749ca137675ac7b4c915418f47.tar.gz core-7a106f7c1220fc749ca137675ac7b4c915418f47.tar.bz2 core-7a106f7c1220fc749ca137675ac7b4c915418f47.zip |
liblog: remove strdup from logging calls
strdup to a static pointer is unnecessary, strlcpy into a static buffer
instead. Avoids allocations in the ALOG* path, allowing liblog to be
used by libmemleak.
Change-Id: Ie0986da27c1fc5eb8ce4ebb076b513be8e1ee676
Diffstat (limited to 'liblog')
-rw-r--r-- | liblog/log_is_loggable.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/liblog/log_is_loggable.c b/liblog/log_is_loggable.c index 0f81efc80..2f8f886bd 100644 --- a/liblog/log_is_loggable.c +++ b/liblog/log_is_loggable.c @@ -110,7 +110,7 @@ static int __android_log_level(const char *tag, int default_prio) * Where the missing tag matches all tags and becomes the * system global default. We do not support ro.log.tag* . */ - static char *last_tag; + static char last_tag[PROP_NAME_MAX]; static uint32_t global_serial; /* some compilers erroneously see uninitialized use. !not_locked */ uint32_t current_global_serial = 0; @@ -149,20 +149,19 @@ static int __android_log_level(const char *tag, int default_prio) if (taglen) { int local_change_detected = change_detected; if (!not_locked) { - if (!last_tag + if (!last_tag[0] || (last_tag[0] != tag[0]) - || strcmp(last_tag + 1, tag + 1)) { + || strncmp(last_tag + 1, tag + 1, sizeof(last_tag) - 1)) { /* invalidate log.tag.<tag> cache */ for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) { tag_cache[i].pinfo = NULL; tag_cache[i].c = '\0'; } - free(last_tag); - last_tag = NULL; + last_tag[0] = '\0'; local_change_detected = 1; } - if (!last_tag) { - last_tag = strdup(tag); + if (!last_tag[0]) { + strncpy(last_tag, tag, sizeof(last_tag)); } } strcpy(key + sizeof(log_namespace) - 1, tag); |