void closewhist(Whist *wh) { int i; if(wh && decref(wh) == 0){ free(wh->title); for(i=0; i<wh->ndoc; i++){ free(wh->doc[i].author); free(wh->doc[i].comment); freepage(wh->doc[i].wtxt); } free(wh->doc); free(wh); } }
void delete_from_page_cache(struct page *page) { struct address_space *mapping = page->mapping; void (*freepage)(struct page *); BUG_ON(!PageLocked(page)); freepage = mapping->a_ops->freepage; spin_lock_irq(&mapping->tree_lock); __delete_from_page_cache(page); spin_unlock_irq(&mapping->tree_lock); mem_cgroup_uncharge_cache_page(page); if (freepage) freepage(page); page_cache_release(page); }
/** * delete_from_page_cache - delete page from page cache * @page: the page which the kernel is trying to remove from page cache * * This must be called only on pages that have been verified to be in the page * cache and locked. It will never put the page into the free list, the caller * has a reference on the page. */ void delete_from_page_cache(struct page *page) { struct address_space *mapping = page->mapping; struct mem_cgroup *memcg; unsigned long flags; void (*freepage)(struct page *); BUG_ON(!PageLocked(page)); freepage = mapping->a_ops->freepage; memcg = mem_cgroup_begin_page_stat(page); spin_lock_irqsave(&mapping->tree_lock, flags); __delete_from_page_cache(page, NULL, memcg); spin_unlock_irqrestore(&mapping->tree_lock, flags); mem_cgroup_end_page_stat(memcg); if (freepage) freepage(page); page_cache_release(page); }
Whist* Brdwhist(Biobuf *b) { int i, current, conflict, c, n; char *author, *comment, *p, *title; uint32_t t; Wdoc *w; Whist *h; if((p = Brdline(b, '\n')) == nil){ werrstr("short read: %r"); return nil; } p[Blinelen(b)-1] = '\0'; p = strcondense(p, 1); title = estrdup(p); w = nil; n = 0; t = -1; author = nil; comment = nil; conflict = 0; current = 0; while((c = Bgetc(b)) != Beof){ if(c != '#'){ p = Brdline(b, '\n'); if(p == nil) break; p[Blinelen(b)-1] = '\0'; switch(c){ case 'D': t = strtoul(p, 0, 10); break; case 'A': free(author); author = estrdup(p); break; case 'C': free(comment); comment = estrdup(p); break; case 'X': conflict = 1; } } else { /* c=='#' */ Bungetc(b); if(n%8 == 0) w = erealloc(w, (n+8)*sizeof(w[0])); w[n].time = t; w[n].author = author; w[n].comment = comment; comment = nil; author = nil; w[n].wtxt = Brdpage(Brdwline, b); w[n].conflict = conflict; if(w[n].wtxt == nil) goto Error; if(!conflict) current = n; n++; conflict = 0; t = -1; } } if(w==nil) goto Error; free(comment); free(author); h = emalloc(sizeof *h); h->title = title; h->doc = w; h->ndoc = n; h->current = current; incref(h); setmalloctag(h, getcallerpc()); return h; Error: free(title); free(author); free(comment); for(i=0; i<n; i++){ free(w[i].author); free(w[i].comment); freepage(w[i].wtxt); } free(w); return nil; }