diff --git a/lib/base/bsearch.c b/lib/base/bsearch.c index 278962172..268cc018d 100644 --- a/lib/base/bsearch.c +++ b/lib/base/bsearch.c @@ -275,11 +275,12 @@ bsearch_common(const char *buf, size_t sz, const char *key, ret = 0; if (val_len && value) { /* Avoid strndup() so we don't need libroken here yet */ - *value = malloc(val_len + 1); - if (!*value) - ret = errno; - (void) memcpy(*value, &buf[val_start], val_len); - (*value)[val_len] = '\0'; + if ((*value = malloc(val_len + 1))) { + (void) memcpy(*value, &buf[val_start], val_len); + (*value)[val_len] = '\0'; + } else { + ret = errno; + } } break; } @@ -708,6 +709,10 @@ _bsearch_file(bsearch_file_handle bfh, const char *key, if (reads) *reads = 0; + if (value) + *value = NULL; + if (loops) + *loops = 0; /* If whole file is in memory then search that and we're done */ if (bfh->file_sz == bfh->cache_sz) @@ -715,11 +720,6 @@ _bsearch_file(bsearch_file_handle bfh, const char *key, /* Else block-wise binary search */ - if (value) - *value = NULL; - if (loops) - *loops = 0; - l = 0; r = (bfh->file_sz / bfh->page_sz) + 1; for (level = 0, page = r >> 1; page >= l && page < r ; level++) { @@ -851,7 +851,7 @@ stdb_copy_value(void *db, heim_string_t table, heim_data_t key, { bsearch_file_handle bfh = db; const char *k; - char *v; + char *v = NULL; heim_data_t value; int ret; @@ -869,6 +869,8 @@ stdb_copy_value(void *db, heim_string_t table, heim_data_t key, else k = (const char *)heim_data_get_ptr(key); ret = _bsearch_file(bfh, k, &v, NULL, NULL, NULL); + if (ret == 0 && v == NULL) + ret = -1; /* Quiet lint */ if (ret != 0) { if (ret > 0 && error) *error = heim_error_create(ret, "%s", strerror(ret)); diff --git a/lib/base/dll.c b/lib/base/dll.c index 31017a011..59c39137b 100644 --- a/lib/base/dll.c +++ b/lib/base/dll.c @@ -83,7 +83,8 @@ struct tls_values { static HEIMDAL_THREAD_LOCAL struct tls_values values; -#define DEAD_KEY ((void *)8) +static char dead_key; +#define DEAD_KEY ((void *)&dead_key) void heim_w32_service_thread_detach(void *unused) diff --git a/lib/base/expand_path.c b/lib/base/expand_path.c index df382b998..f61279a49 100644 --- a/lib/base/expand_path.c +++ b/lib/base/expand_path.c @@ -630,7 +630,6 @@ heim_expand_path_tokensv(heim_context context, break; extra_tokens[i] = strdup(s); if (extra_tokens[i++] == NULL) { - va_end(ap); free_extra_tokens(extra_tokens); return heim_enomem(context); } @@ -639,7 +638,6 @@ heim_expand_path_tokensv(heim_context context, s = ""; extra_tokens[i] = strdup(s); if (extra_tokens[i] == NULL) { - va_end(ap); free_extra_tokens(extra_tokens); return heim_enomem(context); } diff --git a/lib/base/log.c b/lib/base/log.c index 0db015b4f..020a0fbc7 100644 --- a/lib/base/log.c +++ b/lib/base/log.c @@ -205,10 +205,13 @@ open_syslog(heim_context context, heim_log_facility *facility, int min, int max, const char *sev, const char *fac) { - struct _heimdal_syslog_data *sd = malloc(sizeof(*sd)); + struct _heimdal_syslog_data *sd; + heim_error_code ret; int i; - if (sd == NULL) + if (facility == NULL) + return EINVAL; + if ((sd = calloc(1, sizeof(*sd))) == NULL) return heim_enomem(context); i = find_value(sev, syslogvals); if (i == -1) @@ -219,8 +222,11 @@ open_syslog(heim_context context, i = LOG_AUTH; sd->priority |= i; roken_openlog(facility->program, LOG_PID | LOG_NDELAY, i); - return heim_addlog_func(context, facility, min, max, - log_syslog, close_syslog, sd); + ret = heim_addlog_func(context, facility, min, max, log_syslog, + close_syslog, sd); + if (ret) + free(sd); + return ret; } struct file_data { @@ -248,7 +254,7 @@ log_file(heim_context context, const char *timestr, const char *msg, void *data) size_t i = 0; size_t j; - if (logf == NULL || (f->disp & FILEDISP_REOPEN)) { + if (f->filename && (logf == NULL || (f->disp & FILEDISP_REOPEN))) { int flags = O_WRONLY|O_APPEND; int fd; @@ -339,9 +345,9 @@ open_file(heim_context context, heim_log_facility *fac, int min, int max, if (ret) { free(fd->filename); free(fd); - } - if (disp & FILEDISP_KEEPOPEN) + } else if (disp & FILEDISP_KEEPOPEN) { log_file(context, NULL, NULL, fd); + } return ret; } @@ -385,7 +391,7 @@ heim_addlog_dest(heim_context context, heim_log_facility *f, const char *orig) p++; } if (strcmp(p, "STDERR") == 0) { - ret = open_file(context, f, min, max, NULL, NULL, stderr, + ret = open_file(context, f, min, max, NULL, "a", stderr, FILEDISP_KEEPOPEN, 0); } else if (strcmp(p, "CONSOLE") == 0) { /* XXX WIN32 */ @@ -609,10 +615,7 @@ __attribute__ ((__format__ (__printf__, 3, 0))) heim_error_code heim_have_debug(heim_context context, int level) { - heim_log_facility *fac; - - return (context != NULL && - (fac = heim_get_debug_dest(context)) != NULL); + return (context != NULL && heim_get_debug_dest(context) != NULL); } heim_error_code diff --git a/lib/base/plugin.c b/lib/base/plugin.c index df225a939..88d04c03c 100644 --- a/lib/base/plugin.c +++ b/lib/base/plugin.c @@ -590,34 +590,37 @@ add_dso_plugins_load_fn(heim_context context, heim_error_code ret; heim_array_t plugins; heim_plugin_load_t load_fn; - char *sym; + char *sym = NULL; size_t i; heim_get_instance_func_t get_instance; size_t n_ftables; heim_plugin_common_ftable_cp *ftables; - if (asprintf(&sym, "%s_plugin_load", caller->name) == -1) + if (asprintf(&sym, "%s_plugin_load", caller->name) == -1 || sym == NULL) return NULL; /* suppress error here because we may be looking for a different plugin type */ load_fn = (heim_plugin_load_t)dlsym(dsohandle, sym); - free(sym); if (load_fn == NULL) { heim_debug(context, 15, "Symbol %s not found in %s", sym, dsopath); + free(sym); return NULL; } ret = load_fn(pcontext, &get_instance, &n_ftables, &ftables); if (ret) { heim_warn(context, ret, "plugin %s failed to load", dsopath); + free(sym); /* fallback to loading structure directly */ return add_dso_plugin_struct(context, pcontext, dsopath, dsohandle, caller->name); } - if (!validate_plugin_deps(context, caller, dsopath, get_instance)) + if (!validate_plugin_deps(context, caller, dsopath, get_instance)) { + free(sym); return NULL; + } plugins = heim_array_create(); @@ -639,6 +642,7 @@ add_dso_plugins_load_fn(heim_context context, } heim_debug(context, 15, "DSO %s loaded (%s)", dsopath, sym); + free(sym); return plugins; } #endif /* HAVE_DLOPEN */