Exemplo n.º 1
0
static int test_ring(int argc, char **argv)
{
	
	char *p = NULL, *p1 = NULL, *p2 = NULL,*p3 = NULL;
	
	struct ring_buff_cache *buff = malloc(1024);
	if (!buff)
		goto err;
	
	buff = ring_buff_head_init(buff, 2048);
	
	p = ring_buff_alloc(buff, 256);
	if (!p)
		goto err;
	memset((void *)p, 1, 256);
	
	p1 = ring_buff_alloc(buff, 300);
	if (!p1)
		goto err;
	memset((void *)p1, 3, 300);	
	
	p2 = ring_buff_alloc(buff, 123);
	if (!p2)
		goto err;
	memset((void *)p2, 1, 123);	
	
	ring_buff_free(buff, p);
	p = NULL;

	/* DEBUG FOR CURR HEAD INFO */
	cache_package_head_info_debug(buff);
	
	p3 = ring_buff_alloc(buff, 256);
	
	ring_buff_free(buff, p1);
	p1 = NULL;
	
	if (!p3)
		goto err;
	memset((void *)p3, 1, 256);	

	cache_package_head_info_debug(buff);
	
	ring_buff_free(buff, p2);
	ring_buff_free(buff, p3);	
	p2 = NULL;
	p3 = NULL;
	
	cache_package_head_info_debug(buff);
err:
	cache_package_head_info_debug(buff);
	if (buff)
		free(buff);
	
	return 0;
}
Exemplo n.º 2
0
void
dcam_free_resources(dcam_state_t *softc_p)
{
	ixl1394_command_t *ptr;
	ixl1394_command_t *tmp;

	/*
	 *  The following fixes a memory leak.  See bug #4423667.
	 *  The original code  only released memory for the first  frame.
	 */

	/* free ixl opcode resources */
	ptr = softc_p->ixlp;

	while (ptr != NULL) {
		tmp = ptr;
		ptr = ptr->next_ixlp;

		switch (tmp->ixl_opcode) {
			case IXL1394_OP_LABEL:
				kmem_free(tmp, sizeof (ixl1394_label_t));
			break;

			case IXL1394_OP_SET_SYNCWAIT:
				kmem_free(tmp, sizeof (ixl1394_set_syncwait_t));
			break;

			case IXL1394_OP_RECV_PKT_ST:
				kmem_free(tmp, sizeof (ixl1394_xfer_pkt_t));
			break;

			case IXL1394_OP_RECV_BUF:
				kmem_free(tmp, sizeof (ixl1394_xfer_buf_t));
			break;

			case IXL1394_OP_CALLBACK:
				kmem_free(tmp, sizeof (ixl1394_callback_t));
			break;

			case IXL1394_OP_JUMP:
				kmem_free(tmp, sizeof (ixl1394_jump_t));
			break;
		}
	}

	/*
	 * free ring buff and indicate that the resources have been cleared
	 */
	ring_buff_free(softc_p, softc_p->ring_buff_p);

	softc_p->flags &= ~DCAM1394_FLAG_FRAME_RCV_INIT;
	softc_p->ixlp = NULL;
}