static void g_local_file_enumerator_finalize (GObject *object) { GLocalFileEnumerator *local; local = G_LOCAL_FILE_ENUMERATOR (object); if (local->got_parent_info) _g_local_file_info_free_parent_info (&local->parent_info); g_free (local->filename); g_file_attribute_matcher_unref (local->matcher); g_file_attribute_matcher_unref (local->reduced_matcher); if (local->dir) { #ifdef USE_GDIR g_dir_close (local->dir); #else closedir (local->dir); #endif local->dir = NULL; } free_entries (local); G_OBJECT_CLASS (g_local_file_enumerator_parent_class)->finalize (object); }
int hash_table_cleanup(hash_table_t *table) { if (table == NULL) { return 0; } free_entries(table); free(table); table = NULL; return 0; }
static void recycle_entries(List *list, Entry *first_entry, Entry *last_entry) { #ifdef USE_MEM_POOLS last_entry->next = list->entry_pool; list->entry_pool = first_entry; #else last_entry->next = NULL; free_entries(first_entry); #endif }
static int alloc_entries(struct mq_policy *mq, unsigned elts) { unsigned u = mq->nr_entries; INIT_LIST_HEAD(&mq->free); mq->nr_entries_allocated = 0; while (u--) { struct entry *e = kmem_cache_zalloc(mq_entry_cache, GFP_KERNEL); if (!e) { free_entries(mq); return -ENOMEM; } list_add(&e->list, &mq->free); } return 0; }
static void finalize_list(List *list) { free_entries(list->entries); free_entries(list->entry_pool); }
static int apply_new_entries () { int count, i; unsigned long s = 0, t; size_t ofs; zabbix_log (LOG_LEVEL_DEBUG, "apply_active_buffer"); free_entries (); if (!buffer.new_entries) return 1; /* get amount of active checks */ count = i = 0; while (buffer.new_entries[i++].key) count++; zabbix_log (LOG_LEVEL_DEBUG, "apply_active_buffer: count of new checks %d", count); buffer.entries = (buffer_check_entry_t*)malloc (count*sizeof (buffer_check_entry_t)); if (!buffer.entries) return 0; buffer.header_size = sizeof (buffer_signature) + sizeof (unsigned int); buffer.size = count; zabbix_log (LOG_LEVEL_DEBUG, "apply_active_buffer: memory for new entries allocated"); if (count) { for (i = 0; i < count; i++) { buffer.entries[i].key = strdup (buffer.new_entries[i].key); if (buffer.new_entries[i].refresh) s += (entry_size_estimation * 60UL) / buffer.new_entries[i].refresh; else s += (entry_size_estimation * 60UL) / 1; } /* here we have estimation of our buffer space in minutes */ t = (CONFIG_ACTIVE_BUF_SIZE_MB * 1024UL*1024UL) / s; zabbix_log (LOG_LEVEL_DEBUG, "apply_active_buffer: New buffer's estimation time to live is %lu minutes", t); ofs = 0; s = 0; for (i = 0; i < count; i++) { buffer.header_size += strlen (buffer.entries[i].key) + 1 + sizeof (size_t)*2 + sizeof (int)*2; buffer.entries[i].beg_offset = ofs; if (buffer.new_entries[i].refresh) ofs += t*(entry_size_estimation * 60UL) / buffer.new_entries[i].refresh; else ofs += t*(entry_size_estimation * 60UL) / 1; buffer.entries[i].max_offset = ofs; buffer.entries[i].index = 0; buffer.entries[i].count = 0; buffer.entries[i].refresh = buffer.new_entries[i].refresh; buffer.entries[i].max_items = (buffer.entries[i].max_offset-buffer.entries[i].beg_offset) / 6; buffer.entries[i].sizes = (unsigned short*)calloc (sizeof (unsigned short), buffer.entries[i].max_items); buffer.header_size += buffer.entries[i].max_items*sizeof (unsigned short); zabbix_log (LOG_LEVEL_DEBUG, "Item %s: refr: %d, max_items = %d", buffer.entries[i].key, buffer.new_entries[i].refresh, buffer.entries[i].max_items); s += buffer.entries[i].max_offset-buffer.entries[i].beg_offset; } zabbix_log (LOG_LEVEL_DEBUG, "Total size of buffers %d", s); } /* all finished ok */ buffer.new_entries = NULL; flush_buffer (); return 1; }
void simple_file_selector(EFI_HANDLE *im, CHAR16 **title, CHAR16 *name, CHAR16 *filter, CHAR16 **result) { EFI_STATUS status; CHAR16 **entries = NULL; EFI_FILE_INFO *dmp; int count, select, len; CHAR16 *newname, *selected; *result = NULL; if (!name) name = L"\\"; if (!filter) filter = L""; if (!*im) { EFI_HANDLE h; CHAR16 *volname; simple_volume_selector(title, &volname, &h); if (!volname) return; FreePool(volname); *im = h; } newname = AllocatePool((StrLen(name) + 1)*sizeof(CHAR16)); if (!newname) return; StrCpy(newname, name); name = newname; redo: status = simple_dir_filter(*im, name, filter, &entries, &count, &dmp); if (status != EFI_SUCCESS) goto out_free_name; select = console_select(title, entries, 0); if (select < 0) /* ESC key */ goto out_free; selected = entries[select]; /* note that memory used by selected is valid until dmp is freed */ len = StrLen(selected); if (selected[len - 1] == '/') { CHAR16 *newname; /* stay where we are */ if (StrCmp(selected, L"./") == 0) { free_entries(entries, count); FreePool(entries); entries = NULL; FreePool(dmp); goto redo; } else if (StrCmp(selected, L"../") == 0) { int i; i = StrLen(name) - 1; for (i = StrLen(name); i > 0; --i) { if (name[i] == '\\') break; } if (i == 0) i = 1; if (StrCmp(name, L"\\") != 0 && StrCmp(&name[i], L"..") != 0) { name[i] = '\0'; free_entries(entries, count); FreePool(entries); entries = NULL; FreePool(dmp); goto redo; } } newname = AllocatePool((StrLen(name) + len + 2)*sizeof(CHAR16)); if (!newname) goto out_free; StrCpy(newname, name); if (name[StrLen(name) - 1] != '\\') StrCat(newname, L"\\"); StrCat(newname, selected); /* remove trailing / */ newname[StrLen(newname) - 1] = '\0'; free_entries(entries, count); FreePool(entries); entries = NULL; FreePool(dmp); FreePool(name); name = newname; goto redo; } *result = AllocatePool((StrLen(name) + len + 2)*sizeof(CHAR16)); if (*result) { StrCpy(*result, name); if (name[StrLen(name) - 1] != '\\') StrCat(*result, L"\\"); StrCat(*result, selected); } out_free: FreePool(dmp); if (entries) { free_entries(entries, count); FreePool(entries); } out_free_name: FreePool(name); }