コード例 #1
0
ファイル: conn.c プロジェクト: ibright/xunsearch
/**
 * Free cmds list of connection
 * @param conn
 */
void conn_free_cmds(XS_CONN *conn)
{
	XS_CMDS *cmds;

	while ((cmds = conn->zhead) != NULL)
	{
		conn->zhead = cmds->next;
		debug_free(cmds->cmd);
		debug_free(cmds);
	}
	conn->ztail = conn->zhead;
}
コード例 #2
0
ファイル: conn.c プロジェクト: ibright/xunsearch
/**
 * Quit connection
 * @return CMD_RES_QUIT
 */
int conn_quit(XS_CONN *conn, int res)
{
	switch (res)
	{
		case CMD_RES_CLOSED:
			log_info_conn("quit, closed by client");
			break;
		case CMD_RES_IOERR:
			log_error_conn("quit, IO error (ERROR:%s)", strerror(errno));
			break;
		case CMD_RES_NOMEM:
			log_error_conn("quit, out of memory");
			break;
		case CMD_RES_TIMEOUT:
			log_warning_conn("quit, IO timeout (TIMEOUT:%d)", (int) conn->tv.tv_sec);
			break;
		case CMD_RES_STOPPED:
			log_notice_conn("quit, server stopped");
			break;
		case CMD_RES_QUIT:
			log_info_conn("quit, normally");
			break;
		case CMD_RES_ERROR:
			log_warning_conn("quit, result error (CODE:%d)", (int) conn->last_res);
			break;
		case CMD_RES_OTHER:
		default:
			log_warning_conn("quit, unknown reason (RES:%d)", res);
			break;
	}

	// flush all output buffer
	CONN_FLUSH();

	// check to free zcmd
	if (conn->zcmd != NULL && (conn->flag & CONN_FLAG_ZMALLOC))
	{
		debug_free(conn->zcmd);
	}

	// check to free cmds group
	conn_free_cmds(conn);
	// close socket & free-self
	close(CONN_FD());

	debug_free(conn);
	conn_server.num_burst--;
	return CMD_RES_QUIT;
}
コード例 #3
0
ファイル: debug.c プロジェクト: UIKit0/mctrl
void*
debug_realloc(const char* fname, int line, void* mem, size_t size)
{
    void* new_mem;

    new_mem = debug_malloc(fname, line, size);
    if(MC_ERR(new_mem == NULL))
        return NULL;

    /* Copy contents from the old memory chunk */
    if(mem != NULL) {
        mem_info_t* mi;
        mi = mem_hashtable[MEM_HASHTABLE_INDEX(mem)];
        while(mi->mem != mem) {
            if(MC_ERR(mi == NULL)) {
                /* Not registered? */
                MC_TRACE("%s:%d: \tdebug_realloc(%p): Attempting to realloc "
                         "non-allocated memory.", fname, line, mem);
                MC_ASSERT(1 == 0);
            }
            mi = mi->next;
        }
        memcpy(new_mem, mem, MC_MIN(size, mi->size));
        debug_free(fname, line, mem);
    }

    return new_mem;
}
コード例 #4
0
uint64
ExpressionParser::_ParseCommandPipe(int& returnCode)
{
	debugger_command_pipe* pipe = (debugger_command_pipe*)checked_malloc(
		sizeof(debugger_command_pipe));

	pipe->segment_count = 0;
	pipe->broken = false;

	do {
		if (pipe->segment_count >= MAX_DEBUGGER_COMMAND_PIPE_LENGTH)
			parse_exception("Pipe too long", fTokenizer.NextToken().position);

		debugger_command_pipe_segment& segment
			= pipe->segments[pipe->segment_count];
		segment.index = pipe->segment_count++;

		_ParseCommand(segment);

	} while (fTokenizer.NextToken().type == TOKEN_PIPE);

	fTokenizer.RewindToken();

	// invoke the pipe
	returnCode = invoke_debugger_command_pipe(pipe);

	debug_free(pipe);

	return get_debug_variable("_", 0);
}
コード例 #5
0
ファイル: tcp.c プロジェクト: universe-long-zhuo/C-Example01
static void free_wbuf_chain(struct wbuf_chain * wc)
{
	struct wbuf * wb;

	assert(wc != NULL);

	wb = wc->head;
	while (wb) {
		struct wbuf * w = wb;
		debug_tcp_print("freeing wbuf %p", wb);
		wb = wb->next;
		debug_free(w);
	}

	debug_free(wc);
}
コード例 #6
0
ファイル: virtual.c プロジェクト: DanieleDeSensi/mammut
static void vperfctr_free(struct vperfctr *perfctr)
{
	debug_free(perfctr);
	ClearPageReserved(virt_to_page(perfctr));
	free_page((unsigned long)perfctr);
	dec_nrctrs();
}
コード例 #7
0
		void debug_delete(T*& pointer, cstring file, const uint32 line)
		{
			if(pointer != NULL)
				debug_free(pointer, file, line);

			pointer = NULL;
		}
コード例 #8
0
ファイル: tcp.c プロジェクト: universe-long-zhuo/C-Example01
static struct wbuf * wbuf_ack_sent(struct socket * sock, unsigned sz)
{
	struct wbuf_chain * wc = (struct wbuf_chain *) sock->buf;
	struct wbuf ** wb;

	wb = &wc->head;
	while (sz && *wb) {
		if ((*wb)->unacked <= sz) {
			struct wbuf * w;
			assert((*wb)->rem_len == 0);
			w = *wb;
			*wb = w->next;
			sock->buf_size -= w->len;
			sz -= w->unacked;
			debug_tcp_print("whole buffer acked (%d / %d), removed",
					w->unacked, w->len);
			debug_free(w);
		} else {
			(*wb)->unacked -= sz;
			(*wb)->written += sz;
			debug_tcp_print("acked %d / %d bytes", sz, (*wb)->len);
			sz = 0;
		}
	}

	/* did we write out more than we had? */
	assert(sz == 0);

	if (wc->head == NULL)
		wc->tail = NULL;
	debug_tcp_print("buffer size %d\n", sock->buf_size);

	return wc->head;
}
コード例 #9
0
ファイル: meta_mem.c プロジェクト: andreiw/polaris
void
_Free(
	char	*file,
	int	line,
	void	*p
)
{
	debug_free(file, line, p);
}
コード例 #10
0
ファイル: debug.c プロジェクト: nutellarlz/Navination
void *
debug_realloc(const char *where, int line, const char *func, void *ptr, int size)
{
	void *ret = debug_malloc(where, line, func, size);
	if (ret && ptr)
		memcpy(ret, ptr, size);
	debug_free(where, line, func, ptr);
	return ret;
}
コード例 #11
0
		void debug_delete(T*& pointer, cstring file, const uint32 line)
		{
			if(pointer != nullptr)
			{
				pointer->~T();
				debug_free(pointer, file, line);
			}

			pointer = nullptr;
		}
コード例 #12
0
ファイル: gskdebugalloc.c プロジェクト: davebenson/gsk
static gpointer 
debug_realloc     (gpointer mem,
                   gsize    n_bytes)
{
#if 0
  AllocationHeader *header = ((AllocationHeader*)mem) - 1;
  guint old_size;
  assert (memcmp (header->underrun_detection_magic, underrun_detection_magic, 4) == 0);
  assert (memcmp ((char*)(header + 1) + header->size, overrun_detection_magic, 4) == 0);
  assert (header->context->n_bytes_used >= header->size);
  old_size = header->size;

  header = realloc (header, sizeof (AllocationHeader) + n_bytes + 4);
  header->size = n_bytes;
  memcpy ((char*)(header + 1) + n_bytes, overrun_detection_magic, 4);

  header->context->n_bytes_used -= old_size;
  header->context->n_bytes_used += n_bytes;

  return header + 1;
#else
  void *rv;
  guint size;
  if (mem)
    {
      AllocationHeader *header = ((AllocationHeader*)mem) - 1;
      assert (memcmp (header->underrun_detection_magic, underrun_detection_magic, 4) == 0);
      size = header->size;
      assert (memcmp ((char*)(header + 1) + size, overrun_detection_magic, 4) == 0);
      assert (header->context->n_bytes_used >= size);
    }
  else
    size = 0;

  if (log_fd >= 0)
    {
      log_uint (LOG_MAGIC_REALLOC);
      log_pointer (mem);
      log_uint (size);
    }

  stack_levels_to_ignore++;
  rv = debug_malloc (n_bytes);
  memcpy (rv, mem, MIN (n_bytes, size));
  debug_free (mem);
  stack_levels_to_ignore--;

  return rv;
#endif
}
コード例 #13
0
ファイル: debug.c プロジェクト: OS2World/LIB-SDL-2014
void *debug_realloc(void *old_blk, size_t size, char *pcFile, int iLine)
{
  size_t	old_size;
  void		*pBlock = debug_malloc( size, pcFile, iLine );

  old_size = old_blk == NULL ? 0 : *(((size_t *)old_blk) - 1);

  if ( pBlock != NULL && old_blk != NULL )
    memcpy( pBlock, old_blk, min( old_size, size ) );

  if ( ( size == 0 || pBlock != NULL ) && ( old_blk != NULL ) )
    debug_free( old_blk );

  return pBlock;
}
コード例 #14
0
ファイル: tcaMem.c プロジェクト: guillep19/frob
void x_ipcFree(void *item)
#endif
{
  if (item == NULL) return;

#if defined(THINK_C) || defined(macintosh) || defined(__sgi)
  free(item);
#elif defined(DBMALLOC)
  debug_free(file,line,item);
#elif defined(__TURBOC__)
  farfree(item);
#else 
  free(item);
#endif /* THINK_C || macintosh */
}
コード例 #15
0
ファイル: conn.c プロジェクト: ibright/xunsearch
/**
 * Execute zcmd of connection
 * @param conn connection pointer
 * @param func callback handler
 * @return CMD_RES_xxx
 */
int conn_zcmd_exec(XS_CONN *conn, zcmd_exec_t func)
{
	int i, rc = CMD_RES_CONT;
	zcmd_exec_t handlers[] = {conn_zcmd_first, func, conn_server.zcmd_handler, conn_zcmd_last};

	for (i = 0; i < sizeof(handlers) / sizeof(zcmd_exec_t); i++)
	{
		if (handlers[i] == NULL)
			continue;
		rc = (*handlers[i])(conn);
		log_debug_conn("execute zcmd (CMD:%d, FUNC[%d]:%p, RET:0x%04x)",
			conn->zcmd->cmd, i, handlers[i], rc);
		if (rc != CMD_RES_NEXT)
			break;
	}
#ifndef DEBUG
	log_info_conn("zcmd executed (CMD:%d, RET:0x%04x)", conn->zcmd->cmd, rc);
#endif

	// check special flag
	if (rc & CMD_RES_SAVE) // save zcmd into cmds chain
	{
		int rc2 = conn_zcmd_save(conn);
		if (rc2 != CMD_RES_CONT)
			rc = rc2;
	}
	rc &= CMD_RES_MASK;

	// handle special return value
	if (rc == CMD_RES_UNIMP)
	{
		// Not implemented
		log_warning_conn("command not implemented (CMD:%d)", conn->zcmd->cmd);
		rc = XS_CMD_DONT_ANS(conn->zcmd) ? CMD_RES_CONT : CONN_RES_ERR(UNIMP);
	}

	// check to free the zcmd (quit cmd)
	if (conn->flag & CONN_FLAG_ZMALLOC)
	{
		conn->flag ^= CONN_FLAG_ZMALLOC;
		debug_free(conn->zcmd);
	}
	conn->zcmd = NULL;

	// retrun the RC value
	return rc;
}
コード例 #16
0
ファイル: conn.c プロジェクト: ibright/xunsearch
/**
 * Save the current zcmd into cmds list
 * @param conn
 * @return CMD_RES_CONT/CMD_RES_NOMEM
 */
static int conn_zcmd_save(XS_CONN *conn)
{
	XS_CMDS *cmds;

	// change RETURN value to CONT
	log_debug_conn("save command into CMDS (CMD:%d)", conn->zcmd->cmd);

	debug_malloc(cmds, sizeof(XS_CMDS), XS_CMDS);
	if (cmds == NULL)
	{
		log_error_conn("failed to allocate memory for CMDS (SIZE:%d)", sizeof(XS_CMDS));
		return CMD_RES_NOMEM;
	}

	cmds->next = NULL;
	if (conn->flag & CONN_FLAG_ZMALLOC)
	{
		// use zcmd directly
		conn->flag ^= CONN_FLAG_ZMALLOC;
		cmds->cmd = conn->zcmd;
	}
	else
	{
		// copy zcmd
		debug_malloc(cmds->cmd, XS_CMD_SIZE(conn->zcmd), XS_CMD);
		if (cmds->cmd != NULL)
			memcpy(cmds->cmd, conn->zcmd, XS_CMD_SIZE(conn->zcmd));
		else
		{
			log_error_conn("failed to allocate memory for CMDS->cmd (CMD:%d, SIZE:%d)", conn->zcmd->cmd, XS_CMD_SIZE(conn->zcmd));
			debug_free(cmds);
			return CMD_RES_NOMEM;
		}
	}

	// add the cmd to chain of cmds
	if (conn->zhead == NULL)
		conn->ztail = conn->zhead = cmds;
	else
	{
		conn->ztail->next = cmds;
		conn->ztail = cmds;
	}
	return CMD_RES_CONT;
}
コード例 #17
0
void
delete_debug_alloc_pool(debug_alloc_pool* pool)
{
	if (pool == NULL || sCurrentPool == NULL)
		return;

	// find the pool in the hierarchy
	DebugAllocPool* otherPool = sCurrentPool;
	while (otherPool != NULL && otherPool != pool)
		otherPool = otherPool->Parent();

	if (otherPool == NULL)
		return;

	// destroy the pool
	sCurrentPool = pool->Parent();
	pool->Destroy();

	if (pool != &sInitialPool)
		debug_free(pool);
}
コード例 #18
0
ファイル: tracing.cpp プロジェクト: sahil9912/haiku
static void
print_stack_trace(struct tracing_stack_trace* stackTrace,
	const Print& print)
{
	if (stackTrace == NULL || stackTrace->depth <= 0)
		return;

	static const size_t kBufferSize = 256;
	char* buffer = (char*)debug_malloc(kBufferSize);

	for (int32 i = 0; i < stackTrace->depth; i++) {
		addr_t address = stackTrace->return_addresses[i];

		const char* symbol;
		const char* demangledName = NULL;
		const char* imageName;
		bool exactMatch;
		addr_t baseAddress;

		if (elf_debug_lookup_symbol_address(address, &baseAddress, &symbol,
				&imageName, &exactMatch) == B_OK) {

			if (buffer != NULL) {
				bool isObjectMethod;
				demangledName = debug_demangle_symbol(symbol, buffer,
					kBufferSize, &isObjectMethod);
			}

			print("  %p  %s + 0x%lx (%s)%s\n", (void*)address,
				demangledName != NULL ? demangledName : symbol,
				address - baseAddress, imageName,
				exactMatch ? "" : " (nearest)");
		} else
			print("  %p\n", (void*)address);
	}

	if (buffer != NULL)
		debug_free(buffer);
}
コード例 #19
0
ファイル: debug_alloc.cpp プロジェクト: bqqbarbhg/dorfbook
void *debug_reallocate(void *ptr, size_t size, const char *type, size_t type_size, Source_Loc loc)
{
	if (!ptr) {
		return debug_allocate(size, type, type_size, loc);
	} else if (!size) {
		debug_free(ptr, loc);
		return 0;
	}

	os_mutex_lock(&g_debug_memory.lock);

	Debug_Alloc_Header *header = debug_get_header(ptr);

	if (header->state != DEBUG_ALLOC_ALLOCATED_STATE) {
		// Already freed
		assert(0);
	}

	if (header->prev) {
		header->prev->next = header->next;
	}
	if (header->next) {
		header->next->prev = header->prev;
	}
	header->free_loc = loc;

	header->free_trace_length = os_capture_stack_trace(
			header->free_trace,
			Count(header->free_trace));

	U64 old_serial = header->serial;
	Debug_Alloc_Header *logged = unsafe_debug_alloc_get_serial(old_serial);
	if (logged) {
		*logged = *header;
	}

	os_mutex_unlock(&g_debug_memory.lock);

	size_t old_type_size = header->type_size;
	Debug_Alloc_Header *new_header = (Debug_Alloc_Header*)realloc(header, size + sizeof(Debug_Alloc_Header));

	new_header->size = size;
	new_header->alloc_loc = loc;
	new_header->thread_id = os_current_thread_id();
	new_header->prev_serial = old_serial;

	new_header->alloc_trace_length = os_capture_stack_trace(
			new_header->alloc_trace,
			Count(new_header->alloc_trace));

	assert(new_header->type_size == old_type_size);

	os_mutex_lock(&g_debug_memory.lock);

	new_header->serial = ++g_debug_memory.serial;
	new_header->prev = &g_debug_memory.root;
	new_header->next = g_debug_memory.root.next;
	if (g_debug_memory.root.next)
		g_debug_memory.root.next->prev = new_header;
	g_debug_memory.root.next = new_header;

	if (g_debug_memory.log) {
		g_debug_memory.log_index = (g_debug_memory.log_index + 1) % g_debug_memory.log_size;
		g_debug_memory.log[g_debug_memory.log_index] = *new_header;
	}

	Debug_Alloc_Header *old_logged = unsafe_debug_alloc_get_serial(old_serial);
	if (old_logged) {
		old_logged->next_serial = new_header->serial;
	}

#ifdef BREAK_AT_SERIAL
	if (new_header->serial == BREAK_AT_SERIAL)
		os_debug_break();
#endif

	os_mutex_unlock(&g_debug_memory.lock);
	return new_header + 1;
}
コード例 #20
0
ファイル: raw_ip.c プロジェクト: AjeyBohare/minix
static void raw_ip_recv_free(void * data)
{
	if (((struct raw_ip_recv_data *)data)->pbuf)
		pbuf_free(((struct raw_ip_recv_data *)data)->pbuf);
	debug_free(data);
}
コード例 #21
0
ファイル: main.c プロジェクト: erossi/opengarden
/*! main */
int main(void)
{
	struct debug_t *debug;
	struct programs_t *progs;
	struct cmdli_t *cmdli;
	/* convenient pre-allocated structure */
	struct tm *tm_clock;
	char c;

	/* anti warning for non initialized variables */
	debug = NULL;
	progs = NULL;
	cmdli = NULL;
	tm_clock = NULL;

	/* Init sequence, turn on both led */
	led_init();
	led_set(BOTH, ON);

	io_init();
	usb_init();
	debug = debug_init(debug);
	progs = prog_init(progs);
	cmdli = cmdli_init(cmdli);
	tm_clock = date_init(tm_clock, debug);
        set_sleep_mode(SLEEP_MODE_PWR_SAVE);
	sei();
	date_hwclock_start();
	led_set(BOTH, OFF);

	while (1) {
		/* PC is connected but debug is off. */
		if (usb_connected && (!debug->active))
			debug_start(debug);

		if (debug->active && (!usb_connected))
			debug_stop(debug);

		/* If PC is connected
		 * then check for a command sent from the user
		 * and execute it.
		 * Anyway do NOT go to sleep.
		 */
		if (debug->active) {
			c = uart_getchar(0, 0);

			if (c) {
				/* echo */
				uart_putchar(0, c);
				cmdli_exec(c, cmdli, progs, debug);
			}
		} else {
			go_to_sleep(progs->valve, debug);

			if (prog_alarm(progs) && flag_get(progs, FL_LED))
				led_set(RED, BLINK);
		}

		/* if there is a job to do (open, close valves).
		 */
		if (date_timetorun(tm_clock, debug))
			job_on_the_field(progs, debug, tm_clock);
	}

	/* This part should never be reached */
	date_hwclock_stop();
	cli();
	date_free(tm_clock);
	cmdli_free(cmdli);
	prog_free(progs);
	debug_free(debug);

	return(0);
}
コード例 #22
0
ファイル: memory.c プロジェクト: 2pac/kamailio
void debug_free_ex(void *block)
{
	debug_free(block, "<none>", 0);
}
コード例 #23
0
ファイル: u_debug_memory.c プロジェクト: dumbbell/mesa
void *
debug_realloc(const char *file, unsigned line, const char *function,
              void *old_ptr, size_t old_size, size_t new_size )
{
   struct debug_memory_header *old_hdr, *new_hdr;
   struct debug_memory_footer *old_ftr, *new_ftr;
   void *new_ptr;
   
   if(!old_ptr)
      return debug_malloc( file, line, function, new_size );
   
   if(!new_size) {
      debug_free( file, line, function, old_ptr );
      return NULL;
   }
   
   old_hdr = header_from_data(old_ptr);
   if(old_hdr->magic != DEBUG_MEMORY_MAGIC) {
      debug_printf("%s:%u:%s: reallocating bad or corrupted memory %p\n",
                   file, line, function,
                   old_ptr);
      debug_assert(0);
      return NULL;
   }
   
   old_ftr = footer_from_header(old_hdr);
   if(old_ftr->magic != DEBUG_MEMORY_MAGIC) {
      debug_printf("%s:%u:%s: buffer overflow %p\n",
                   old_hdr->file, old_hdr->line, old_hdr->function,
                   old_ptr);
      debug_assert(0);
   }

   /* alloc new */
   new_hdr = os_malloc(sizeof(*new_hdr) + new_size + sizeof(*new_ftr));
   if(!new_hdr) {
      debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n",
                   file, line, function,
                   (long unsigned)new_size);
      return NULL;
   }
   new_hdr->no = old_hdr->no;
   new_hdr->file = old_hdr->file;
   new_hdr->line = old_hdr->line;
   new_hdr->function = old_hdr->function;
   new_hdr->size = new_size;
   new_hdr->magic = DEBUG_MEMORY_MAGIC;
   new_hdr->tag = 0;
#if DEBUG_FREED_MEMORY
   new_hdr->freed = FALSE;
#endif
   
   new_ftr = footer_from_header(new_hdr);
   new_ftr->magic = DEBUG_MEMORY_MAGIC;
   
   pipe_mutex_lock(list_mutex);
   LIST_REPLACE(&old_hdr->head, &new_hdr->head);
   pipe_mutex_unlock(list_mutex);

   /* copy data */
   new_ptr = data_from_header(new_hdr);
   memcpy( new_ptr, old_ptr, old_size < new_size ? old_size : new_size );

   /* free old */
   old_hdr->magic = 0;
   old_ftr->magic = 0;
   os_free(old_hdr);

   return new_ptr;
}
コード例 #24
0
ファイル: debug.c プロジェクト: nutellarlz/Navination
void debug_free_func(void *ptr)
{
	debug_free("unknown", 0, "unknown", ptr);
}
コード例 #25
0
		void debug_free_with_null(T*& pointer, cstring file, const uint32 line)
		{
			debug_free(pointer, file, line);

			pointer = nullptr;
		}
コード例 #26
0
ファイル: stralloc_freedebug.c プロジェクト: rsenn/shish
void stralloc_freedebug(const char *file, unsigned int line, stralloc *sa) {
  if (sa->s) debug_free(file, line, sa->s);
  sa->s = 0;
}
コード例 #27
0
ファイル: vdebugnew.cpp プロジェクト: AmesianX/vdream
void operator delete[] (void* p, const char* file, const int line)
{
  debug_new_log("delete[](%p, %s, %d)\n", p, file, line);
  return debug_free(p, file, line);
}
コード例 #28
0
ファイル: vdebugnew.cpp プロジェクト: AmesianX/vdream
void  operator delete[] (void* p)
{
  debug_new_log("delete[](%p)\n", p);
  return debug_free(p, "unknown", 0);
}
コード例 #29
0
		void debug_delete_array(T*& pointer, cstring file, const uint32 line)
		{
			debug_free(pointer, file, line);

			pointer = nullptr;
		}
コード例 #30
0
ファイル: debug_new.cpp プロジェクト: edbee/edbee-lib
/// the delete operator
void operator delete (void* p) throw()
{
    return debug_free(p, "unknown", 0);
}