* Calculate aproximated value of zram usage for selected process
* by formula: proc_zram_usage = ( VmSwap x ZramMemoryUsage )/SwapTotal
*/
- *usage = ((float)((proc_swap_usage*BYTE_TO_KBYTE(zram_usage))/swap_total));
+ *usage = (int)((float)proc_swap_usage * BYTE_TO_KBYTE(zram_usage) / swap_total);
return RESOURCED_ERROR_NONE;
}
{
struct meminfo mi;
int ret;
- char error_buf[256];
ret = proc_get_meminfo(&mi, MEMINFO_MASK_SWAP_TOTAL);
if (ret < 0) {
- _E("Failed to get %s: %s",
- meminfo_id_to_string(MEMINFO_ID_SWAP_TOTAL),
- strerror_r(-ret, error_buf, sizeof(error_buf)));
+ _E("Failed to get %s: %m",
+ meminfo_id_to_string(MEMINFO_ID_SWAP_TOTAL));
return 0;
}
k = strndup(buf, l);
if (!k)
- return -ENOMEM;
+ return -errno;
id = meminfo_string_to_id(k);
if (id < 0 || id >= MEMINFO_ID_MAX)
static void pipe_exit(void)
{
if (phandler) {
- remove_fd_read_handler(phandler);
+ remove_fd_read_handler(&phandler);
phandler = NULL;
}
return RESOURCED_ERROR_NONE;
}
-static const struct module_ops resourced_helper_worker_ops = {
+static struct module_ops resourced_helper_worker_ops = {
.priority = MODULE_PRIORITY_HIGH,
.name = "resourced-helper-worker",
.init = resourced_worker_init,
userinfo_for_each(elem, user_list) {
cache = (struct heart_cpu_dat_cache*)malloc(sizeof(struct heart_cpu_dat_cache));
+ assert(cache);
+
cache->path = strndup(elem->home_dir, strlen(elem->home_dir));
cache->list = g_hash_table_new_full(
g_str_hash,
func(format, ##arg); \
pthread_mutex_unlock(&(module->cache_mutex)); \
sqlite3_finalize(db_elem->insert_stmt); \
+ db_elem->insert_stmt = NULL; \
return; \
} } while (0)
static void logging_free_db_value(gpointer data)
{
struct logging_db *db_elem = (struct logging_db*)data;
- if (db_elem->insert_stmt)
+ if (db_elem->insert_stmt) {
sqlite3_finalize(db_elem->insert_stmt);
+ db_elem->insert_stmt = NULL;
+ }
if (db_elem->file)
sqlite3_close(db_elem->file);
if (db_elem->path)
goto error;
}
db_elem = (struct logging_db*)malloc(sizeof(struct logging_db));
+ assert(db_elem);
+
db_elem->path = strndup(db_path, sizeof(db_path));
+ assert(db_elem->path);
+
db_elem->file = db_file;
db_elem->insert_stmt = NULL;
g_hash_table_insert(module->db_list, GINT_TO_POINTER(UID_FOR_ROOT), (gpointer)db_elem);
struct memory_limit_event *mle = (struct memory_limit_event *)data;
close(mle->fd);
free(mle->path);
- remove_fd_read_handler(mle->fdh);
+ remove_fd_read_handler(&(mle->fdh));
free(mle);
}