Example #1
0
struct strings *strings_new() {
    struct strings *strings = malloc(sizeof(*strings));
    if (!strings) {
        return NULL;
    }

    strings->hashes = block_new(PAGE_SIZE);
    strings->strings = block_new(PAGE_SIZE);
    strings->index = block_new(PAGE_SIZE);
    if (!strings->hashes || !strings->strings || !strings->index) {
        goto error;
    }

    tree_new(&strings->hash_map);

    strings->total = 0;
    strings->hash_seed = 5381;

    return strings;

error:
    if (strings->hashes) {
        block_free(strings->hashes);
    }
    if (strings->strings) {
        block_free(strings->strings);
    }
    if (strings->index) {
        block_free(strings->index);
    }
    free(strings);
    return NULL;
}
Example #2
0
libspectrum_error
libspectrum_rzx_finalise( libspectrum_rzx *rzx )
{
  GSList *list, *item, *next_item;
  rzx_block_t *block, *next_block;
  libspectrum_error error;
  int first_snap = 1;
  int finalised = 0;

  /* Delete interspersed snapshots */
  list = rzx->blocks;

  while( list ) {
    item = list;
    block = list->data;
    list = list->next;

    if( block->type == LIBSPECTRUM_RZX_SNAPSHOT_BLOCK ) {
      if( first_snap ) {
        first_snap = 0;
      } else {
        block_free( block );
        rzx->blocks = g_slist_delete_link( rzx->blocks, item );
        finalised = 1;
      }
    }
  }

  /* Merge adjacent input blocks */
  list = rzx->blocks;

  while( list ) {
    block = list->data;

    if( block->type == LIBSPECTRUM_RZX_INPUT_BLOCK ) {

      next_item = list->next;
      if( !next_item ) break;

      next_block = next_item->data;

      if( next_block->type == LIBSPECTRUM_RZX_INPUT_BLOCK ) {
        error = input_block_merge( &( block->types.input ),
                                   &( next_block->types.input ) );
        if( error ) return error;

        block_free( next_block );
        rzx->blocks = g_slist_delete_link( rzx->blocks, next_item );
        finalised = 1;
      } else {
        list = list->next;
      }

    } else {
      list = list->next;
    }
  }

  return finalised? LIBSPECTRUM_ERROR_NONE : LIBSPECTRUM_ERROR_INVALID;
}
Example #3
0
//Coalesce free blocks if possible
static void *coalesce(void *bp) {
    size_t prev_alloc = block_free(block_prev(get_header(bp)));
    size_t next_alloc = block_free(block_next(get_header(bp)));
    size_t size = block_size(get_header(bp));

    if(prev_alloc && next_alloc)
	return bp;
    else if(prev_alloc && !next_alloc) {
	size += block_size(block_next(get_header(bp)));
	PUT(get_header(bp), PACK(size, 0));
	PUT(get_footer(bp), PACK(size, 0));
    }
    else if(!prev_alloc && next_alloc) {
	size += block_size(block_prev(get_header(bp)));
	PUT(get_header(prev_bp(bp)), PACK(size, 0));
	PUT(get_footer(bp), PACK(size, 0));
	bp = prev_bp(bp);
    }
    else if(!prev_alloc && !next_alloc) {
	size += block_size(block_next(get_header(bp))) + block_size(block_prev(get_header(bp)));
	PUT(get_header(prev_bp(bp)), PACK(size, 0));
	PUT(get_footer(next_bp(bp)), PACK(size, 0));
	bp = prev_bp(bp);
    }
    checkheap(1);
    return bp;
}
Example #4
0
static void inst_free(struct inst* i) {
  jv_mem_free(i->symbol);
  block_free(i->subfn);
  block_free(i->arglist);
  if (opcode_describe(i->op)->flags & OP_HAS_CONSTANT) {
    jv_free(i->imm.constant);
  }
  jv_mem_free(i);
}
Example #5
0
/*
 * Merge block with adjacent free blocks
 * Return: the pointer to the new free block 
 */
static void *coalesce(void *block) {
    REQUIRES(block != NULL);
    REQUIRES(in_heap(block));

    uint32_t *prev_block = block_prev(block);
    uint32_t *next_block = block_next(block);
    int prev_free = block_free(prev_block);
    int next_free = block_free(next_block);
    unsigned int words = block_size(block);
    

    if (prev_free && next_free) {       // Case 4, both free

        block_delete(prev_block);
        block_delete(next_block);

        words += block_size(prev_block) + block_size(next_block) + 4;
        set_size(prev_block, words);
        block_mark(prev_block, FREE);
        block = (void *)prev_block;

        block_insert(block);
        ENSURES(in_list(block));    
    }

    else if (!prev_free && next_free) { // Case 2, next if free

        block_delete(next_block);

        words += block_size(next_block) + 2;
        set_size(block, words);
        block_mark(block, FREE);  

        block_insert(block);
        ENSURES(in_list(block));      
    }

    else if (prev_free && !next_free) { // Case 3, prev is free
        block_delete(prev_block);

        words += block_size(prev_block) + 2;
        set_size(prev_block, words);
        block_mark(prev_block, FREE);
        block = (void *)prev_block;

        block_insert(block);
        ENSURES(in_list(block));
    }

    else {                              // Case 1, both unfree
        block_insert(block);
        ENSURES(in_list(block));
        return block;
    }
    return block;
 } 
Example #6
0
/* Codec clear coded unit - not sure where this should go - away? :-) */
int
codec_clear_coded_unit(coded_unit *u)
{
        if (u->state_len) {
                assert(u->state != NULL);
                block_free(u->state, u->state_len);
        }
        if (u->data_len) {
                assert(u->data != NULL);
                block_free(u->data, u->data_len);
        }
        memset(u, 0, sizeof(coded_unit));
        return TRUE;
}
Example #7
0
PUBLIC
unsigned long
Slab_cache::reap()		// request that cache returns memory to system
{
  Slab *s = 0;
  unsigned long sz = 0;

  for (;;)
    {
	{
	  auto guard = lock_guard(lock);

	  s = _empty.front();
	  // nothing to free
	  if (!s)
	    return 0;

	  cxx::H_list<Slab>::remove(s);
	}

      // explicitly call destructor to delete s;
      s->~Slab();
      block_free(reinterpret_cast<char *>(s + 1) - _slab_size, _slab_size);
      sz += _slab_size;
    }

  return sz;
}
Example #8
0
/*
 * Extends the heap with a new free block
 * Return: the pointer to the new free block 
 *         NULL on error.
 */
static void *extend_heap(unsigned int words) {
    REQUIRES(words > 4);

    uint32_t *block;
    uint32_t *next;
    

    /* Ask for 2 more words for header and footer */
    words = (words % 2) ? (words + 1) : words;
    if (VERBOSE)
        printf("Extend Words = %d bytes\n", words * 4);
    if ((long)(block = mem_sbrk(words * WSIZE)) == -1)
        return NULL;

    block--;          // back step 1 since the last one is the epi block
    set_size(block, words - 2);
    block_mark(block, FREE);

    ENSURES(block != NULL);
    // New eqilogue block
    next = block_next(block);    
    set_size(next, 0);
    *next |= 0x40000000;
    //block_mark(block_next(block), ALLOCATED);

    ENSURES(!block_free(next));
    ENSURES(block_size(next) == 0);
    block = coalesce(block);    // Coalesce if necessary
    ENSURES(in_list(block));
    return block;
 }
Example #9
0
void
PyArena_Free(PyArena *arena)
{
    int r;
    assert(arena);
#if defined(Py_DEBUG)
    /*
    fprintf(stderr,
        "alloc=%d size=%d blocks=%d block_size=%d big=%d objects=%d\n",
        arena->total_allocs, arena->total_size, arena->total_blocks,
        arena->total_block_size, arena->total_big_blocks,
        PyList_Size(arena->a_objects));
    */
#endif
    block_free(arena->a_head);
    /* This property normally holds, except when the code being compiled
       is sys.getobjects(0), in which case there will be two references.
    assert(arena->a_objects->ob_refcnt == 1);
    */

    /* Clear all the elements from the list.  This is necessary
       to guarantee that they will be DECREFed. */
    r = PyList_SetSlice(arena->a_objects,
                        0, PyList_GET_SIZE(arena->a_objects), NULL);
    assert(r == 0);
    assert(PyList_GET_SIZE(arena->a_objects) == 0);
    Py_DECREF(arena->a_objects);
    free(arena);
}
Example #10
0
int
lpc_repair (uint16_t idx, u_char *state, uint16_t consec_lost,
            coded_unit *prev, coded_unit *missing, coded_unit *next)
{
        lpc_txstate_t *lps;

        assert(prev);
        assert(missing);

        if (missing->data) {
                debug_msg("lpc_repair: missing unit had data!\n");
                block_free(missing->data, missing->data_len);
        }

        missing->data     = (u_char*)block_alloc(LPCTXSIZE);
        missing->data_len = LPCTXSIZE;

        assert(prev->data);
        assert(prev->data_len == LPCTXSIZE);
        memcpy(missing->data, prev->data, LPCTXSIZE);

        lps = (lpc_txstate_t*)missing->data;
        lps->gain = (u_char)((float)lps->gain * 0.8f);

        UNUSED(next);
        UNUSED(consec_lost);
        UNUSED(state);
        UNUSED(idx);

        return TRUE;
}
Example #11
0
PyArena *
PyArena_New()
{
    PyArena* arena = (PyArena *)malloc(sizeof(PyArena));
    if (!arena)
        return (PyArena*)PyErr_NoMemory();

    arena->a_head = block_new(DEFAULT_BLOCK_SIZE);
    arena->a_cur = arena->a_head;
    if (!arena->a_head) {
        free((void *)arena);
        return (PyArena*)PyErr_NoMemory();
    }
    arena->a_objects = PyList_New(0);
    if (!arena->a_objects) {
        block_free(arena->a_head);
        free((void *)arena);
        return (PyArena*)PyErr_NoMemory();
    }
#if defined(Py_DEBUG)
    arena->total_allocs = 0;
    arena->total_size = 0;
    arena->total_blocks = 1;
    arena->total_block_size = DEFAULT_BLOCK_SIZE;
    arena->total_big_blocks = 0;
#endif
    return arena;
}
Example #12
0
void *_dbg_realloc(void *oldp, size_t size)
{
	u8_t *newp;
	struct block *oldblock, *newblock;
	
	LOG(("_dbg_realloc; oldp=0x%x; size=0x%x\n", oldp, size));
	assert(oldp); /* enforced by regular realloc */
	assert(size > 0); /* enforced by regular realloc */

	/* always allocate new block */
	newblock = block_alloc(size);
	if (!newblock)
		return NULL;

	/* copy the data */
	oldblock = block_find(oldp);
	memcpy(block_get_dataptr(newblock), 
		block_get_dataptr(oldblock), 
		MIN(newblock->size, oldblock->size));
		
	/* deallocate old block */
	block_free(oldblock);
	
	newp = block_get_dataptr(newblock);
	LOG(("_dbg_realloc; newp=0x%x\n", newp));
	return newp;
}
Example #13
0
CTEST(node_serial_test, leaf_empty)
{
	int ret = 0;
	int fd = ness_os_open(BRT_FILE, O_RDWR | O_CREAT, 0777);
	struct block *b = block_new();
	struct hdr *hdr = (struct hdr*)xcalloc(1, sizeof(*hdr));
	struct options *opts = options_new();

	/*
	 * dummy brt leaf
	 */
	uint64_t nid = 3;

	struct node *dummy_leaf = leaf_alloc_empty(nid);
	leaf_alloc_bsm(dummy_leaf);
	ret = serialize_node_to_disk(fd, b, dummy_leaf, hdr);
	ASSERT_TRUE(ret > 0);
	//free
	node_free(dummy_leaf);

	struct node *dummy_leaf1;
	ret = deserialize_node_from_disk(fd, b, nid, &dummy_leaf1, 0);
	ASSERT_TRUE(ret > 0);
	ASSERT_EQUAL(0, basement_count(dummy_leaf1->u.l.le->bsm));
	//free
	node_free(dummy_leaf1);

	ness_os_close(fd);
	block_free(b);
	xfree(hdr);
	options_free(opts);
	xcheck_all_free();
}
Example #14
0
/* Destroys all the configuration data. */
void
config_free(void)
{

	if (Global != NULL)
		block_free(Global);
}
Example #15
0
void
pb_flush (pb_t *pb)
{
        pb_node_t *curr, *next, *stop;
        uint16_t i, n_iterators;

	pb_validate(pb);
        stop  = pb->psentinel;
        curr  = stop->next; /* next = head */

        while(curr != stop) {
                next = curr->next;
                curr->next->prev = curr->prev;
                curr->prev->next = curr->next;
                pb->freeproc(&curr->data, curr->data_len);
                pb->n_nodes--;
                assert(curr->data == NULL);
                block_free(curr, sizeof(pb_node_t));
                curr = next;
        }
        
        assert(stop->next  == stop);
        assert(stop->prev  == stop);
        assert(pb->n_nodes == 0);

        /* Reset all iterators */
        n_iterators = pb->n_iterators;
        for(i = 0; i < n_iterators; i++) {
                pb->iterators[i].node = stop;
        }
	pb_validate(pb);
}
Example #16
0
void
sinc_convert (const converter_fmt_t *cfmt,
              u_char *state,
              sample* src_buf, int src_len,
              sample *dst_buf, int dst_len)
{
        sinc_state_t *s;
        int channels;
        sample *tmp_buf;
        int     tmp_len;

        channels = cfmt->src_channels;

        s = (sinc_state_t*)state;

        if (cfmt->src_channels == 2 && cfmt->dst_channels == 1) {
                /* stereo->mono then sample rate change */
                if (s->steps) {
                        /* inplace conversion needed */
                        converter_change_channels(src_buf, src_len, 2, src_buf, src_len / 2, 1);
                        src_len /= 2;
                } else {
                        /* this is only conversion */
                        converter_change_channels(src_buf, src_len, 2, dst_buf, dst_len, 1);
                        return;
                }
                channels = 1;
        } else if (cfmt->src_channels == 1 && cfmt->dst_channels == 2) {
                dst_len /= 2;
        }

        switch(s->steps) {
        case 1:
                assert(s->fs[0].fn);
                        s->fs[0].fn(&s->fs[0], src_buf, src_len, dst_buf, dst_len);
                break;
        case 2:
                /* first step is downsampling */
                tmp_len  = src_len / s->fs[0].scale;
                tmp_buf = (sample*)block_alloc(sizeof(sample) * tmp_len);
                assert(s->fs[0].fn);
                assert(s->fs[1].fn);

                s->fs[0].fn(&s->fs[0], src_buf, src_len, tmp_buf, tmp_len);
                s->fs[1].fn(&s->fs[1], tmp_buf, tmp_len, dst_buf, dst_len);
                block_free(tmp_buf, tmp_len * sizeof(sample));
        }

        if (cfmt->src_channels == 1 && cfmt->dst_channels == 2) {
                /* sample rate change before mono-> stereo */
                if (s->steps) {
                        /* in place needed */
                        converter_change_channels(dst_buf, dst_len, 1, dst_buf, dst_len * 2, 2);
                } else {
                        /* this is our only conversion here */
                        converter_change_channels(src_buf, src_len, 1, dst_buf, dst_len * 2, 2);
                }
        }
}
Example #17
0
static HANDLE open_dsp(Devtab_t* dp, Pfd_t* fdp, Path_t *ip, int oflags, HANDLE *extra)
{
	HANDLE hp;
	int blkno, minor = ip->name[1];
	Pdev_t *pdev;
	unsigned short *blocks = devtab_ptr(Share->chardev_index, AUDIO_MAJOR);

	if(load_audio())
	{

		/* If the device is already opened */
		if(blkno = blocks[minor])
		{
			logerr(LOG_DEV+5, "Device Busy");
			errno = EBUSY;
			return 0;
		}
		else
		{
			WAVEFORMATEX *wp;
			if((blkno = block_alloc(BLK_PDEV)) == 0)
				return(0);
			pdev = dev_ptr(blkno);
			wp = (WAVEFORMATEX*)(pdev+1);
			ZeroMemory((void *)pdev, BLOCK_SIZE-1);
			/* Initialising the wave format sturcture */
			wp->wFormatTag=WAVE_FORMAT_PCM;
			wp->nChannels=CHANNELS;
			wp->nSamplesPerSec=SAMPLES_PER_SEC;
			if(minor&1)
				wp->nSamplesPerSec *= 2;
			wp->wBitsPerSample=BITS_PER_SAMPLE;
			wp->nBlockAlign=(wp->wBitsPerSample*CHANNELS)/8 ;
			wp->nAvgBytesPerSec=wp->nSamplesPerSec*wp->nBlockAlign;
			wp->cbSize=EXTRA_FORMAT_SIZE;
			if(!audio_open(pdev,1))

			{
				logerr(LOG_DEV+5, "waveOutOpen");
				block_free((unsigned short)blkno);
				return 0;
			}
			hp = AUDIO_HANDLE;
			pdev->major=AUDIO_MAJOR;
			pdev->minor = minor;
			uwin_pathmap(ip->path, pdev->devname, sizeof(pdev->devname), UWIN_W2U);

			fdp->devno = blkno;
			blocks[minor] = blkno;
			pdev->devpid = P_CP->pid;
		}
		return hp;
	}
	else
	{
		logerr(0, "audio functions not supported");
		return 0;
	}
}
Example #18
0
void
libspectrum_rzx_iterator_delete( libspectrum_rzx *rzx,
				 libspectrum_rzx_iterator it )
{
  block_free( it->data );

  rzx->blocks = g_slist_delete_link( rzx->blocks, it );
}
Example #19
0
int main(int argc, char **argv) {
  struct block *block = block_new();
  parse(stdin, block);
  print_basic(stdout, block);
  block_free(block);

  return 0;
}
Example #20
0
// Returns 0 if no errors were found, otherwise returns the error
int mm_checkheap(int verbose) {
    printf("\n\nCheckheap begins!\n\n");
    printf("Heap (%p):\n", (void *)heap_ptr);
    uint32_t *ptr = (uint32_t *)heap_ptr;
    unsigned int bsize = block_size(ptr);
    while(bsize > 0) {
	printf("%p:: %x::\t", (void *)ptr, *ptr);
	printf("Header: Block size= %x\t Block Allocated= %d\n", bsize, block_free(ptr));
        ptr = block_next(ptr);
        bsize = block_size(ptr);
    }
    printf("%p:: %x::\t", (void *)ptr, *ptr);
    printf("Header: Block size= %x\t Block Allocated= %d\n", bsize, block_free(ptr));
    printf("End of checkheap\n\n");
    verbose = verbose;
    return 0;
}
Example #21
0
void static_allocator_destroy(StaticAllocator *sa)
{
	zend_uint i;

	for (i=0; i<sa->num_blocks; i++) {
		block_free(&sa->Blocks[i]);
	}
	efree(sa->Blocks);
}
Example #22
0
static void
sinc_downsample_mono(struct s_filter_state *fs,
                      sample *src, int src_len,
                      sample *dst, int dst_len)
{
        int32_t *hc, *he, t, work_len;

        sample *work_buf, *ss, *sc, *de, *d;

        work_len = src_len + fs->taps;
        work_buf = (sample*)block_alloc(work_len * sizeof(sample));

        /* Get samples into work_buf */
        memcpy(work_buf, fs->hold_buf, fs->hold_bytes);
        memcpy(work_buf + fs->hold_bytes / sizeof(sample), src, src_len * sizeof(sample));

        /* Save last samples in src into hold_buf for next time */
        if (src_len >= (int)(fs->hold_bytes / sizeof(sample))) {
                memcpy(fs->hold_buf,
                       src + src_len - fs->hold_bytes / sizeof(sample),
                       fs->hold_bytes);
        } else {
                /* incoming chunk was shorter than hold buffer */
                memmove(fs->hold_buf,
                        fs->hold_buf + src_len,
                        fs->hold_bytes - src_len * sizeof(sample));
                memcpy(fs->hold_buf + fs->hold_bytes / sizeof(sample) - src_len,
                       src,
                       src_len * sizeof(sample));
        }

        d  = dst;
        de = dst + dst_len;
        sc = ss = work_buf;
        he      = fs->filter + fs->taps;

        while (d != de) {
                t = 0;
                hc = fs->filter;
                while(hc < he) {
                        t += (*sc) * (*hc);
                        sc++;
                        hc++;
                }
                t = t / SINC_SCALE;
                clip16(t);
                *d = (sample) t;

                d++;
                ss += fs->scale;
                sc = ss;
        }

        assert(d  == dst + dst_len);
        block_free(work_buf, work_len * sizeof(sample));
        xmemchk();
}
Example #23
0
File: hfile.c Project: pipul/lab
block_t *block_load(int32_t fd, int32_t offset, int32_t size)
{
	block_t *l;
	entry_t *o;
	int32_t len;
	int8_t *buffer, *ptr;
	
	if (fd < 0 || offset < 0 || size < 0)
		return(NULL);
	if ((l = block_new()) == NULL)
		return(NULL);
	if ((buffer = malloc(size)) == NULL)
		__ERROR_LOG(B_ERROR);
	lseek(fd,offset,SEEK_SET);
	if (size != read(fd,buffer,size))
		__ERROR_LOG(R_ERROR);

	ptr = buffer;
	l->magic = *(uint64_t *)ptr;
	ptr = ptr + sizeof(uint64_t);
	if (l->magic != crc32_encode(ptr,size - sizeof(uint64_t)))
		__ERROR_LOG(C_ERROR);

	while (ptr - buffer < size) {
		if ((o = entry_new()) == NULL)
			continue;
		len = *(int32_t *)ptr;
		ptr = ptr + sizeof(int32_t);
		o->key = sdsnnew(ptr,len);
		ptr = ptr + len;

		len = *(int32_t *)ptr;
		ptr = ptr + sizeof(int32_t);
		o->value = sdsnnew(ptr,len);
		ptr = ptr + len;
		
		if (o->key && o->value) {
			block_add(l,o);
			continue;
		}
		if (o->key)
			sdsdel(o->key);
		if (o->value)
			sdsdel(o->value);
	}

	free(buffer);
	return(l);

C_ERROR:
R_ERROR:
	free(buffer);
B_ERROR:
	block_free(l);
	return(NULL);
}
Example #24
0
void _dbg_free(void *ptr)
{
	LOG(("_dbg_free; ptr=0x%x\n", ptr));
	assert(ptr); /* enforced by regular free */

	/* find the block and free it */
	block_free(block_find(ptr));

	LOG(("_dbg_free done\n"));
}
Example #25
0
//Find the first fit
static void *find_first_fit(size_t size) {
    uint32_t *ptr = (uint32_t *)heap_ptr + 2;
    unsigned int bsize = block_size(ptr);
    while(bsize > 0) {
	if((size <= bsize) && !block_free(ptr))
	    return (void *)block_mem(ptr);
	ptr = block_next(ptr);
	bsize = block_size(ptr);
    }
    return NULL;
}
Example #26
0
PUBLIC
void *
Slab_cache::alloc()	// request initialized member from cache
{
  void *unused_block = 0;
  void *ret;
    {
      auto guard = lock_guard(lock);

      Slab *s = get_available_locked();

      if (EXPECT_FALSE(!s))
	{
	  guard.reset();

	  char *m = (char*)block_alloc(_slab_size, _slab_size);
	  Slab *new_slab = 0;
	  if (m)
	    new_slab = new (m + _slab_size - sizeof(Slab)) Slab(_elem_num, _entry_size, m);

	  guard.lock(&lock);

	  // retry gettin a slab that might be allocated by a different
	  // CPU meanwhile
	  s = get_available_locked();

	  if (!s)
	    {
	      // real OOM
	      if (!m)
		return 0;

	      _partial.add(new_slab);
	      s = new_slab;
	    }
	  else
	    unused_block = m;
	}

      ret = s->alloc();
      assert(ret);

      if (s->is_full())
	{
	  cxx::H_list<Slab>::remove(s);
	  _full.add(s);
	}
    }

  if (unused_block)
    block_free(unused_block, _slab_size);

  return ret;
}
Example #27
0
void block_destroy(block_t *l)
{
	entry_t *e;

	while (l->_head->forward[0]) {
		e = l->_head->forward[0]->forward[0];
		entry_destroy(l->_head->forward[0]);
		l->_head->forward[0] = e;
	}
	entry_destroy(l->_head);
	block_free(l);
}
Example #28
0
void
media_data_destroy(media_data **ppmd, uint32_t md_size)
{
        media_data *pmd;
        coded_unit *pcu;
        int         i;

        pmd = *ppmd;

        assert(pmd != NULL);
        assert(md_size == sizeof(media_data));

        for(i = 0; i < pmd->nrep; i++) {
                pcu = pmd->rep[i];
                if (pcu->state) {
                        block_free(pcu->state, pcu->state_len);
                        pcu->state     = 0;
                        pcu->state_len = 0;
                }
                assert(pcu->state_len == 0);
                if (pcu->data) {
                        block_free(pcu->data, pcu->data_len);
                        pcu->data     = 0;
                        pcu->data_len = 0;
                }
                assert(pcu->data_len == 0);
                block_free(pcu, sizeof(coded_unit));
        }
#ifdef DEBUG_MEM
        for(i = pmd->nrep; i < MAX_MEDIA_UNITS; i++) {
                if (pmd->rep[i] != NULL) {
                        assert(pmd->rep[i]->state == NULL);
                        assert(pmd->rep[i]->data  == NULL);
                }
        }
#endif /* DEBUG_MEM */

        block_free(pmd, sizeof(media_data));
        *ppmd = NULL;
}
Example #29
0
static int free_dsp(Pdev_t *pdev, int noclose)
{
	if(pdev->count != 0)
	logmsg(LOG_DEV+5, "free_dsp: bad reference count=%d", pdev->count);
	if(pdev->major)
	{
		unsigned short *blocks = devtab_ptr(Share->chardev_index,pdev->major);
		unsigned short blkno = blocks[pdev->minor];
		blocks[pdev->minor] = 0;
		block_free(blkno);
	}
	return(0);
}
Example #30
0
block block_bind_referenced(block binder, block body, int bindflags) {
  assert(block_has_only_binders(binder, bindflags));
  bindflags |= OP_HAS_BINDING;
  block refd = gen_noop();
  for (inst* curr; (curr = block_take(&binder));) {
    block b = inst_block(curr);
    if (block_bind_subblock(b, body, bindflags)) {
      refd = BLOCK(refd, b);
    } else {
      block_free(b);
    }
  }
  return block_join(refd, body);
}