void mixer_source_free(MIXER_SOURCE_T *pSource) { if(!pSource) { return; } pSource->active = 0; pthread_mutex_lock(&s_mixer_mtx); if(pSource->id > 0 && s_mixer_source_id > 0) { s_mixer_source_id--; } pthread_mutex_unlock(&s_mixer_mtx); audio_preproc_free(&pSource->preproc); ringbuf_free(&pSource->buf); if(pSource->pOutput) { ringbuf_free(&pSource->pOutput->buf); if(pSource->pOutput->vad_buffer) { free(pSource->pOutput->vad_buffer); pSource->pOutput->vad_buffer = NULL; } free(pSource->pOutput); pSource->pOutput = NULL; } free(pSource); }
/* * Frees all memory allocated by the ringbuffer */ void ringbuf_error_cleanup(void) { unsigned int i; /* try to close via wtap */ if (rb_data.pdh != NULL) { if (fclose(rb_data.pdh) == 0) { rb_data.fd = -1; } rb_data.pdh = NULL; } /* close directly if still open */ if (rb_data.fd != -1) { ws_close(rb_data.fd); rb_data.fd = -1; } if (rb_data.files != NULL) { for (i=0; i < rb_data.num_files; i++) { if (rb_data.files[i].name != NULL) { ws_unlink(rb_data.files[i].name); } } } /* free the memory */ ringbuf_free(); }
/* * Frees all memory allocated by the ringbuffer */ void ringbuf_error_cleanup(void) { unsigned int i; /* try to close via wtap */ if (rb_data.pdh != NULL) { if (libpcap_dump_close(rb_data.pdh, NULL)) { rb_data.fd = -1; } rb_data.pdh = NULL; } /* close directly if still open */ /* XXX - it shouldn't still be open; "libpcap_dump_close()" should leave the file closed even if it fails */ if (rb_data.fd != -1) { ws_close(rb_data.fd); rb_data.fd = -1; } if (rb_data.files != NULL) { for (i=0; i < rb_data.num_files; i++) { if (rb_data.files[i].name != NULL) { ws_unlink(rb_data.files[i].name); } } } /* free the memory */ ringbuf_free(); }
struct hfp_gw *hfp_gw_new(int fd) { struct hfp_gw *hfp; if (fd < 0) return NULL; hfp = new0(struct hfp_gw, 1); if (!hfp) return NULL; hfp->fd = fd; hfp->close_on_unref = false; hfp->read_buf = ringbuf_new(4096); if (!hfp->read_buf) { free(hfp); return NULL; } hfp->write_buf = ringbuf_new(4096); if (!hfp->write_buf) { ringbuf_free(hfp->read_buf); free(hfp); return NULL; } hfp->io = io_new(fd); if (!hfp->io) { ringbuf_free(hfp->write_buf); ringbuf_free(hfp->read_buf); free(hfp); return NULL; } hfp->cmd_handlers = queue_new(); if (!hfp->cmd_handlers) { io_destroy(hfp->io); ringbuf_free(hfp->write_buf); ringbuf_free(hfp->read_buf); free(hfp); return NULL; } if (!io_set_read_handler(hfp->io, can_read_data, hfp, read_watch_destroy)) { queue_destroy(hfp->cmd_handlers, destroy_cmd_handler); io_destroy(hfp->io); ringbuf_free(hfp->write_buf); ringbuf_free(hfp->read_buf); free(hfp); return NULL; } hfp->writer_active = false; hfp->result_pending = false; return hfp_gw_ref(hfp); }
static void window_free(Win *win) { if (!win) return; Editor *ed = win->editor; if (ed && ed->ui) ed->ui->window_free(win->ui); view_free(win->view); ringbuf_free(win->jumplist); free(win); }
int wait_fill_buffer(irc_connection *con) { unsigned free = ringbuf_free(con); unsigned right = IRC_BUFFER_SIZE - con->wpos; free = MIN(free, right); int recvd = recv_string(con, con->buf + con->wpos, free); con->wpos = (con->wpos + recvd) % IRC_BUFFER_SIZE; con->buf[con->wpos] = '\0'; return recvd; }
void hfp_hf_unref(struct hfp_hf *hfp) { if (!hfp) return; if (__sync_sub_and_fetch(&hfp->ref_count, 1)) return; io_set_write_handler(hfp->io, NULL, NULL, NULL); io_set_read_handler(hfp->io, NULL, NULL, NULL); io_set_disconnect_handler(hfp->io, NULL, NULL, NULL); io_destroy(hfp->io); hfp->io = NULL; if (hfp->close_on_unref) close(hfp->fd); hfp_hf_set_debug(hfp, NULL, NULL, NULL); ringbuf_free(hfp->read_buf); hfp->read_buf = NULL; ringbuf_free(hfp->write_buf); hfp->write_buf = NULL; queue_destroy(hfp->event_handlers, destroy_event_handler); hfp->event_handlers = NULL; queue_destroy(hfp->cmd_queue, free); hfp->cmd_queue = NULL; if (!hfp->in_disconnect) { free(hfp); return; } hfp->destroyed = true; }
static void window_free(Win *win) { if (!win) return; Vis *vis = win->vis; for (Win *other = vis->windows; other; other = other->next) { if (other->parent == win) other->parent = NULL; } if (vis->ui) vis->ui->window_free(win->ui); view_free(win->view); for (size_t i = 0; i < LENGTH(win->modes); i++) map_free(win->modes[i].bindings); ringbuf_free(win->jumplist); free(win); }
static int acd_release(const char *path, struct fuse_file_info *fi){ file_ctx * ctx = (file_ctx *) fi->fh; fprintf(stderr, "RELEASE start: %s\n", path); //Stop htto thread ctx->abort_curl=1;//stop curl callbacks ctx->thread_done=1;//kill the thread ringbuf_reset(ctx->rb); //empty current buffer to force a callback loop fprintf(stderr, "RELEASE writemutex: %s\n", path); pthread_join(ctx->curlthread, NULL); // wait for thread to end //Free the memory pthread_mutex_destroy(&ctx->writemutex); pthread_mutex_destroy(&ctx->readmutex); curl_easy_cleanup(ctx->curl); free(ctx->url); //string ringbuf_free(&ctx->rb);//ringbuffer free(ctx); fprintf(stderr, "RELEASE done: %s\n", path); }
int main() { ringbuf *r; size_t sz; int rc; char *d; r = ringbuf_new(11); printf("putting 7 bytes into buffer of sz 11\n"); rc = ringbuf_put(r, z, 7); printf("put: %s\n", (rc == -1) ? "failed" : "ok"); printf("consuming 7\n"); ringbuf_mark_consumed(r, 7); printf("next put of > 4 bytes wraps buffer, writing 5\n"); rc = ringbuf_put(r, z, 5); printf("put: %s\n", (rc == -1) ? "failed" : "ok"); sz = ringbuf_get_next_chunk(r, &d); printf("chunk sz %lu: sz, %.*s\n", sz, (int)sz, d); printf("reading 3, of 5 available\n"); ringbuf_mark_consumed(r, 3); printf("next read is last byte before wrapping\n"); sz = ringbuf_get_next_chunk(r, &d); printf("chunk sz %lu: sz, %.*s\n", sz, (int)sz, d); ringbuf_mark_consumed(r, 1); printf("next read starts reading from wrapped part\n"); sz = ringbuf_get_next_chunk(r, &d); printf("chunk sz %lu: sz, %.*s\n", sz, (int)sz, d); ringbuf_mark_consumed(r, 1); printf("nothing left\n"); sz = ringbuf_get_pending_size(r); printf("size = %lu\n", sz); ringbuf_free(r); return 0; }
static void oss_quit(void) { mainloop_time_source_free(play_source); ringbuf_free(oss_output_buffer); }
int main() { ringbuf *r; r = ringbuf_new(100); ringbuf_free(r); return 0; }
struct hfp_hf *hfp_hf_new(int fd) { struct hfp_hf *hfp; if (fd < 0) return NULL; hfp = new0(struct hfp_hf, 1); if (!hfp) return NULL; hfp->fd = fd; hfp->close_on_unref = false; hfp->read_buf = ringbuf_new(4096); if (!hfp->read_buf) { free(hfp); return NULL; } hfp->write_buf = ringbuf_new(4096); if (!hfp->write_buf) { ringbuf_free(hfp->read_buf); free(hfp); return NULL; } hfp->io = io_new(fd); if (!hfp->io) { ringbuf_free(hfp->write_buf); ringbuf_free(hfp->read_buf); free(hfp); return NULL; } hfp->event_handlers = queue_new(); if (!hfp->event_handlers) { io_destroy(hfp->io); ringbuf_free(hfp->write_buf); ringbuf_free(hfp->read_buf); free(hfp); return NULL; } hfp->cmd_queue = queue_new(); if (!hfp->cmd_queue) { io_destroy(hfp->io); ringbuf_free(hfp->write_buf); ringbuf_free(hfp->read_buf); queue_destroy(hfp->event_handlers, NULL); free(hfp); return NULL; } hfp->writer_active = false; if (!io_set_read_handler(hfp->io, hf_can_read_data, hfp, read_watch_destroy)) { queue_destroy(hfp->event_handlers, destroy_event_handler); io_destroy(hfp->io); ringbuf_free(hfp->write_buf); ringbuf_free(hfp->read_buf); free(hfp); return NULL; } return hfp_hf_ref(hfp); }
void free_echo_watcher(echo_io *w) { ringbuf_free(&(w->buf.rb)); free(w); }