Esempio n. 1
0
void *acl_default_malloc(const char *filename, int line, size_t len)
{
	const char *myname = "acl_default_malloc";
	size_t new_len;
	char *ptr;
	MBLOCK *real_ptr;
	const char *pname = NULL;

	if (filename && *filename)
		SET_FILE(pname, filename);
	else
		pname = __FILENAME_UNKNOWN;

	if (len < 1)
		acl_msg_fatal("%s(%d), %s: malloc: length %ld invalid",
			pname, line, myname, (long) len);

	new_len = SPACE_FOR(len);
	if (new_len <= 0)
		acl_msg_fatal("%s(%d): new_len(%d) <= 0",
			myname, __LINE__, (int) new_len);
	else if (new_len >= __malloc_limit) {
		acl_log_strace();
		acl_msg_warn("%s(%d): new_len(%d) too large",
			myname, __LINE__, (int) new_len);
	}

#ifdef	_USE_GLIB
	if ((real_ptr = (MBLOCK *) g_malloc(new_len)) == 0) {
		acl_log_strace();
		acl_msg_error("%s(%d)->%s: new_len: %d, g_malloc error(%s)",
			pname, line, myname, (int) new_len, strerror(errno));
		return 0;
	}
#else
	if ((real_ptr = (MBLOCK *) malloc(new_len)) == 0) {
		acl_log_strace();
		acl_msg_error("%s(%d)->%s: malloc: insufficient memory: %s, "
			"new_len: %d", pname, line, myname,
			strerror(errno), (int) new_len);
		return 0;
	}
#endif
	CHECK_OUT_PTR(ptr, real_ptr, len);
#if 0
	memset(ptr, FILLER, len);
#endif

	return ptr;
}
Esempio n. 2
0
void acl_msg_panic(const char *fmt,...)
{
	va_list ap;

	va_start (ap, fmt);

	if (__pre_write_fn)
		__pre_write_fn(__pre_write_ctx, fmt, ap);

	if (__log_open_flag) {
		if (__write_fn != NULL)
			__write_fn(__msg_ctx, fmt, ap);
		else
			acl_write_to_log2("panic", fmt, ap);
	} else if (__stdout_enable) {
#ifdef LINUX
		printf("acl_msg_panic->pid(%d), ", getpid());
#elif defined(SOLARIS)
		printf("acl_msg_panic->pid(%ld), ", getpid());
#endif
		vprintf(fmt, ap);
		printf("\r\n");
	}

	va_end (ap);

	acl_log_strace();
	acl_close_log();
	acl_assert(0);
}
Esempio n. 3
0
void acl_default_free(const char *filename, int line, void *ptr)
{
	const char *myname = "acl_default_free";
	MBLOCK *real_ptr;
	size_t len;
	const char *pname = NULL;

	if (filename && *filename)
		SET_FILE(pname, filename);
	else
		pname = __FILENAME_UNKNOWN;

	if (ptr == NULL) {
		acl_log_strace();
		acl_msg_error("%s(%d)->%s: ptr null", pname, line, myname);
		return;
	}

# ifndef NO_SHARED_EMPTY_STRINGS
	if (ptr != empty_string) {
# endif
		CHECK_IN_PTR(ptr, real_ptr, len, pname, line);
/*
		memset((char *) real_ptr, FILLER, SPACE_FOR(len));
*/
#ifdef	_USE_GLIB
		g_free(real_ptr);
#else
		free((char *) real_ptr);
#endif
# ifndef NO_SHARED_EMPTY_STRINGS
	} 
# endif
}
Esempio n. 4
0
void *acl_default_realloc(const char *filename, int line,
	void *ptr, size_t len)
{
	const char *myname = "acl_default_realloc";
	MBLOCK *real_ptr;
	size_t old_len, new_len;
	const char *pname = NULL;

	if (filename && *filename)
		SET_FILE(pname, filename);
	else
		pname = __FILENAME_UNKNOWN;

#ifndef NO_SHARED_EMPTY_STRINGS
	if (ptr == empty_string)
		return acl_default_malloc(pname, line, len);
#endif

	if (len < 1)
		acl_msg_fatal("%s(%d)->%s: realloc: requested length %ld",
			pname, line, myname, (long) len);
	CHECK_IN_PTR(ptr, real_ptr, old_len, pname, line);

	new_len = SPACE_FOR(len);
	if (new_len <= 0)
		acl_msg_fatal("%s(%d): new_len(%d) <= 0",
			myname, __LINE__, (int) new_len);
	else if (new_len >= __malloc_limit) {
		acl_log_strace();
		acl_msg_warn("%s(%d): new_len(%d) too large",
			myname, __LINE__, (int) new_len);
	}

#ifdef	_USE_GLIB
	if ((real_ptr = (MBLOCK *) g_realloc((char *) real_ptr, new_len)) == 0)
		acl_msg_fatal("%s(%d)->%s: realloc: insufficient memory: %s",
			pname, line, myname, strerror(errno));
#else
	if ((real_ptr = (MBLOCK *) realloc((char *) real_ptr, new_len)) == 0)
		acl_msg_fatal("%s(%d)->%s: realloc: insufficient memory: %s",
			pname, line, myname, strerror(errno));
#endif
	CHECK_OUT_PTR(ptr, real_ptr, len);
#if 0
	if (len > old_len)
		memset((char *) ptr + old_len, FILLER, len - old_len);
#endif

	return ptr;
}
Esempio n. 5
0
void acl_msg_fatal_status2(int status, const char *fmt, va_list ap)
{
	status = status;
	if (__log_open_flag) {
		if (__write_fn != NULL)
			__write_fn(__msg_ctx, fmt, ap);
		else
			acl_write_to_log2("fatal", fmt, ap);
	} else if (__stdout_enable) {
#ifdef LINUX
		printf("acl_msg_fatal_status->pid(%d), ", getpid());
#elif defined(SOLARIS)
		printf("acl_msg_fatal_status->pid(%ld), ", getpid());
#endif
		vprintf(fmt, ap);
		printf("\r\n");
	}

	acl_log_strace();
	acl_close_log();
	acl_assert(0);
}