void ary_destroy_i(void **ary, void (*free_elem)(void *p)) { int i; for (i = ary_sz(ary) - 1; i >= 0; i--) { free_elem(ary[i]); } ary_free(ary); }
static struct list_elem *read_file(const gchar *filename, int diag) { gchar *full_filename = NULL; GKeyFile *settingsfile = NULL; struct list_elem *list_item = NULL; if(diag) { if( !(full_filename = g_strconcat(CONF_DIR_DIAG_PATH, "/", filename, NULL)) ) goto cleanup; } else { if( !(full_filename = g_strconcat(CONF_DIR_PATH, "/", filename, NULL)) ) goto cleanup; } if( !(settingsfile = g_key_file_new()) ) goto cleanup; if( !g_key_file_load_from_file(settingsfile, full_filename, G_KEY_FILE_NONE, NULL) ) goto cleanup; if( !(list_item = calloc(1, sizeof *list_item)) ) goto cleanup; list_item->name = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_NAME_KEY, NULL); log_debug("Appname = %s\n", list_item->name); list_item->launch = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_LAUNCH_KEY, NULL); log_debug("Launch = %s\n", list_item->launch); list_item->mode = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_MODE_KEY, NULL); log_debug("Launch mode = %s\n", list_item->mode); list_item->systemd = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_SYSTEMD_KEY, NULL); log_debug("Systemd control = %d\n", list_item->systemd); list_item->post = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_POST, NULL); list_item->state = APP_STATE_DONTCARE; cleanup: if(settingsfile) g_key_file_free(settingsfile); g_free(full_filename); /* if a minimum set of required elements is not filled in we discard the list_item */ if( list_item && !(list_item->name && list_item->mode) ) { log_debug("Element invalid, discarding\n"); free_elem(list_item); list_item = 0; } return list_item; }
static struct list_elem *read_file(const gchar *filename) { gchar *full_filename = NULL; GKeyFile *settingsfile = NULL; struct list_elem *list_item = NULL; if( !(full_filename = g_strconcat(CONF_DIR_PATH, "/", filename, NULL)) ) goto cleanup; if( !(settingsfile = g_key_file_new()) ) goto cleanup; if( !g_key_file_load_from_file(settingsfile, full_filename, G_KEY_FILE_NONE, NULL) ) goto cleanup; if( !(list_item = calloc(1, sizeof *list_item)) ) goto cleanup; list_item->name = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_NAME_KEY, NULL); log_debug("Appname = %s\n", list_item->name); list_item->launch = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_LAUNCH_KEY, NULL); log_debug("Launch = %s\n", list_item->launch); list_item->mode = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_MODE_KEY, NULL); log_debug("Launch mode = %s\n", list_item->mode); list_item->upstart = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_UPSTART_KEY, NULL); log_debug("Upstart control = %d\n", list_item->upstart); cleanup: if(settingsfile) g_key_file_free(settingsfile); g_free(full_filename); /* if not all the elements are filled in we discard the list_item */ if( list_item && !(list_item->launch && list_item->name && list_item->mode) ) { free_elem(list_item), list_item = 0; } return list_item; }
void free_list(linked_list *list,int free_ptr){ while(list->head) free_elem(list->head,free_ptr); free(list); }
void ary_delete_i(void **ary, int index, void (*free_elem)(void *p)) { free_elem(ary_remove(ary, index)); }
static void free_elem_cb(gpointer elem, gpointer user_data) { (void)user_data; free_elem(elem); }