8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 06:03:02 +01:00

Clean up.

1. gds__alloc doesn't throw
2. Add NOMEM handlers to a couple places
3. kill HAVE_*SNPRINTF conditionals
This commit is contained in:
skidder 2004-03-09 00:17:07 +00:00
parent 637336b720
commit b6e5ccd413
26 changed files with 214 additions and 173 deletions

View File

@ -27,7 +27,7 @@
*
*____________________________________________________________
*
* $Id: alice_meta.epp,v 1.32 2004-03-07 07:58:06 robocop Exp $
* $Id: alice_meta.epp,v 1.33 2004-03-09 00:16:49 skidder Exp $
*/
#include "firebird.h"
@ -319,6 +319,14 @@ static TDR get_description(ISC_QUAD* blob_id)
const USHORT length = snarf_blob(blob_id, (USHORT) sizeof(buffer), buffer);
if (length) {
p = bigger_buffer = (TEXT *) gds__alloc((SLONG) length);
if(!p) {
tdgbl->status[0] = isc_arg_gds;
tdgbl->status[1] = isc_virmemexh;
tdgbl->status[2] = isc_arg_end;
ALICE_print_status(tdgbl->status);
return NULL;
}
snarf_blob(blob_id, length, bigger_buffer);
}

View File

@ -32,7 +32,7 @@
* Contributor(s):
*
*
* $Id: alloc.cpp,v 1.42 2004-03-07 07:58:25 robocop Exp $
* $Id: alloc.cpp,v 1.43 2004-03-09 00:16:55 skidder Exp $
*
*/
@ -255,6 +255,24 @@ void* MemoryPool::allocate(size_t size, SSHORT type
return result;
}
void* MemoryPool::allocate_nothrow(size_t size, SSHORT type
#ifdef DEBUG_GDS_ALLOC
, const char* file, int line
#endif
) {
lock.enter();
void* result = internal_alloc(size, type
#ifdef DEBUG_GDS_ALLOC
, file, line
#endif
);
if (needSpare) updateSpare();
lock.leave();
// test with older behavior
// memset(result,0,size);
return result;
}
bool MemoryPool::verify_pool() {
#ifdef TESTING_ONLY
lock.enter();

View File

@ -34,7 +34,7 @@
* Contributor(s):
*
*
* $Id: alloc.h,v 1.34 2004-03-07 07:58:25 robocop Exp $
* $Id: alloc.h,v 1.35 2004-03-09 00:16:55 skidder Exp $
*
*/
@ -196,6 +196,12 @@ public:
#endif
);
void* allocate_nothrow(size_t size, SSHORT type = 0
#ifdef DEBUG_GDS_ALLOC
, const char* file = NULL, int line = 0
#endif
);
void deallocate(void* block);
bool verify_pool();

View File

@ -263,13 +263,8 @@ ISC_STATUS stuff_exception(ISC_STATUS *status_vector, const std::exception& ex,
// Other random C++ exceptions
char temp[256];
#ifdef HAVE_SNPRINTF
snprintf(temp, sizeof(temp)-1, "Unexpected C++ exception (class=\"%s\", what()=\"%s\")",
SNPRINTF(temp, sizeof(temp)-1, "Unexpected C++ exception (class=\"%s\", what()=\"%s\")",
ex_type.name(), ex.what());
#else
sprintf(temp, "Unexpected C++ exception (class=\"%s\", what()=\"%s\")",
ex_type.name(), ex.what());
#endif
temp[sizeof(temp) - 1] = 0;
*status_vector++ = isc_arg_gds;
*status_vector++ = isc_random;

View File

@ -1813,11 +1813,7 @@ static void trace_line(const char* message, ...) {
char buffer[1024];
va_list params;
va_start(params, message);
#ifdef HAVE_VSNPRINTF
vsnprintf(buffer, sizeof(buffer), message, params);
#else
vsprintf(buffer, message, params);
#endif
VSNPRINTF(buffer, sizeof(buffer), message, params);
va_end(params);
buffer[sizeof(buffer) - 1] = 0;
gds__trace_raw(buffer);
@ -3693,10 +3689,15 @@ static USHORT get_plan_info(
&join_count, &level))
{
// assume we have run out of room in the buffer, try again with a larger one
buffer_ptr =
reinterpret_cast<char*>(gds__alloc(BUFFER_XLARGE));
buffer_length = BUFFER_XLARGE;
char* temp = reinterpret_cast<char*>(gds__alloc(BUFFER_XLARGE));
if (!temp) {
// NOMEM. Do not attempt one more try
i++;
continue;
} else {
buffer_ptr = temp;
buffer_length = BUFFER_XLARGE;
}
break;
}
}

View File

@ -92,6 +92,9 @@ void HSHD_init(void)
#endif
UCHAR* p = (UCHAR *) gds__alloc(sizeof(DSQL_SYM) * HASH_SIZE);
// This is appropriate to throw exception here, callers check for it
if(!p) throw std::bad_alloc();
memset(p, 0, sizeof(DSQL_SYM) * HASH_SIZE);
hash_table = (DSQL_SYM *) p;

View File

@ -3793,6 +3793,9 @@ static void set_generator( DUDLEY_NOD node)
current_blr.str_current = current_blr.str_start =
reinterpret_cast<UCHAR *>(gds__alloc(1028));
if (!current_blr.str_current) {
DDL_error_abort(NULL, 14, 0, 0, 0, 0, 0); /* msg 14: memory exhausted */
}
current_blr.str_length = 1028;
#ifdef DEBUG_GDS_ALLOC
@ -3817,6 +3820,9 @@ static void set_generator( DUDLEY_NOD node)
*number = new_val - gen_value;
new_blr.str_current = new_blr.str_start =
reinterpret_cast<UCHAR*>(gds__alloc(1028));
if (!new_blr.str_current) {
DDL_error_abort(NULL, 14, 0, 0, 0, 0, 0); /* msg 14: memory exhausted */
}
new_blr.str_length = 1028;
#ifdef DEBUG_GDS_ALLOC
@ -3907,6 +3913,8 @@ static void store_blr( DUDLEY_NOD node, ISC_QUAD* blob_id, DUDLEY_REL relation)
blr.str_current = blr.str_start =
reinterpret_cast<UCHAR*>(gds__alloc(4096));
if (!blr.str_current)
DDL_error_abort(NULL, 14, 0, 0, 0, 0, 0); /* msg 14: memory exhausted */
blr.str_length = 4096;
#ifdef DEBUG_GDS_ALLOC

View File

@ -118,6 +118,8 @@ void TRN_translate(void)
dyn = &d;
dyn->str_current = dyn->str_start =
reinterpret_cast<UCHAR*>(gds__alloc(8192));
if (!dyn->str_current)
DDL_error_abort(NULL, 14, 0, 0, 0, 0, 0); /* msg 14: memory exhausted */
dyn->str_length = 8192;
#ifdef DEBUG_GDS_ALLOC

View File

@ -3740,6 +3740,10 @@ static void expand_buffers(TDBB tdbb, ULONG number)
* Expand the cache to at least a given number of buffers. If
* it's already that big, don't do anything.
*
* Nickolay Samofatov, 08-Mar-2004.
* This function does not handle exceptions correctly,
* it looks like good handling requires rewrite.
*
**************************************/
SET_TDBB(tdbb);
Database* dbb = tdbb->tdbb_database;
@ -3827,6 +3831,7 @@ static void expand_buffers(TDBB tdbb, ULONG number)
if (!num_in_seg) {
memory = (UCHAR *)gds__alloc((SLONG) dbb->dbb_page_size *
(num_per_seg + 1));
// NOMEM: crash!
LLS_PUSH(memory, &new_block->bcb_memory);
memory = (UCHAR *) (((U_IPTR) memory + dbb->dbb_page_size - 1) &
~((int) dbb->dbb_page_size - 1));

View File

@ -49,7 +49,7 @@
*
*/
/*
$Id: common.h,v 1.106 2004-03-08 18:44:24 skidder Exp $
$Id: common.h,v 1.107 2004-03-09 00:17:02 skidder Exp $
*/
#ifndef JRD_COMMON_H
@ -932,6 +932,12 @@ typedef struct
#define VSNPRINTF(a,b,c,d) vsprintf(a,c,d)
#endif
#ifdef HAVE_SNPRINTF
#define SNPRINTF snprintf
#else
#define SNPRINTF(buffer, length, ...) sprintf(buffer, __VA_ARGS__)
#endif
#define IMPLEMENT_TRACE_ROUTINE(routine, subsystem) \
void routine(const char* message, ...) { \
static const char name_facility[] = subsystem ","; \

View File

@ -4127,30 +4127,23 @@ static void put_summary_blob(blb* blob, RSR_T type, bid* blob_id)
return;
// Go ahead and open blob
blb* blr = BLB_open(tdbb, dbb->dbb_sys_trans, blob_id);
fb_assert(blr->blb_length <= MAX_USHORT);
USHORT length = (USHORT)blr->blb_length;
UCHAR* buffer = (length > sizeof(temp)) ?
(UCHAR*) gds__alloc((SLONG) blr->blb_length) : temp;
// Setup to cleanup after any error that may occur
UCHAR *buffer = (length > sizeof(temp)) ?
FB_NEW(*getDefaultMemoryPool()) UCHAR[blr->blb_length] : temp;
try {
length = (USHORT)BLB_get_data(tdbb, blr, buffer, (SLONG) length);
put_summary_record(blob, type, buffer, length);
}
catch (const std::exception& ex) {
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
if (buffer != temp) {
gds__free(buffer);
}
ERR_punt();
catch (const std::exception&) {
if (buffer != temp)
delete[] buffer;
throw;
}
if (buffer != temp) {
gds__free(buffer);
}
if (buffer != temp)
delete[] buffer;
}
@ -4174,7 +4167,7 @@ static void put_summary_record(blb* blob,
UCHAR temp[129];
UCHAR* buffer = ((size_t) (length + 1) > sizeof(temp)) ?
(UCHAR *) gds__alloc((SLONG) (length + 1)) : temp;
FB_NEW(*getDefaultMemoryPool()) UCHAR[length + 1] : temp;
UCHAR* p = buffer;
@ -4189,17 +4182,14 @@ static void put_summary_record(blb* blob,
try {
BLB_put_segment(tdbb, blob, buffer, (USHORT)(p - buffer));
}
catch (const std::exception& ex) {
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
if (buffer != temp) {
gds__free(buffer);
}
ERR_punt();
catch (const std::exception&) {
if (buffer != temp)
delete[] buffer;
throw;
}
if (buffer != temp) {
gds__free(buffer);
}
if (buffer != temp)
delete[] buffer;
}

View File

@ -274,12 +274,12 @@ void* API_ROUTINE gds__alloc_debug(SLONG size_request,
const TEXT* filename,
ULONG lineno)
{
return getDefaultMemoryPool()->allocate(size_request, 0, filename, lineno);
return getDefaultMemoryPool()->allocate_nothrow(size_request, 0, filename, lineno);
}
#else
void* API_ROUTINE gds__alloc(SLONG size_request)
{
return getDefaultMemoryPool()->allocate(size_request);
return getDefaultMemoryPool()->allocate_nothrow(size_request);
}
#endif

View File

@ -888,7 +888,7 @@ int INF_request_info(const jrd_req* request,
if (!OPT_access_path(request, buffer_ptr, sizeof(buffer), &length))
{
buffer_ptr = (SCHAR *) gds__alloc(BUFFER_XLARGE);
buffer_ptr = FB_NEW(*getDefaultMemoryPool()) char[BUFFER_XLARGE];
OPT_access_path(request, buffer_ptr, BUFFER_XLARGE, &length);
}
break;
@ -947,7 +947,7 @@ int INF_request_info(const jrd_req* request,
info = INF_put_item(item, length, buffer_ptr, info, end);
if (buffer_ptr != buffer) {
gds__free(buffer_ptr);
delete[] buffer_ptr;
buffer_ptr = buffer;
}

View File

@ -1427,6 +1427,12 @@ void ISC_exception_post(ULONG sig_num, const TEXT* err_msg)
* When we got a sync exception, fomulate the error code
* write it to the log file, and abort.
*
* 08-Mar-2004, Nickolay Samofatov.
* This function is dangerous and requires rewrite using signal-safe operations only.
* Main problem is that we call a lot of signal-unsafe functions from this signal handler,
* examples are gds__alloc, gds__log, etc... sprintf is safe on some BSD platforms,
* but not on Linux. This may result in lock-up during signal handling.
*
**************************************/
if (!SCH_thread_enter_check())
THREAD_ENTER;
@ -1440,6 +1446,7 @@ void ISC_exception_post(ULONG sig_num, const TEXT* err_msg)
}
TEXT* log_msg = (TEXT *) gds__alloc(strlen(err_msg) + 256);
// NOMEM: crash!
log_msg[0] = '\0';
switch (sig_num) {
@ -1523,6 +1530,7 @@ ULONG ISC_exception_post(ULONG except_code, const TEXT* err_msg)
}
TEXT* log_msg = (TEXT*) gds__alloc(strlen(err_msg) + 256);
// NOMEM: crash!
log_msg[0] = '\0';
switch (except_code) {

View File

@ -6159,6 +6159,7 @@ TEXT* JRD_num_attachments(TEXT* const buf, USHORT buf_len, USHORT flag,
sizeof(TEXT) *
dbb->
dbb_filename->str_length));
if (!dbfp) throw std::bad_alloc();
dbf = dbfp;
}
else {
@ -6167,6 +6168,7 @@ TEXT* JRD_num_attachments(TEXT* const buf, USHORT buf_len, USHORT flag,
(sizeof(struct dbf) +
sizeof(TEXT) *
dbb->dbb_filename->str_length));
if (!dbfp) throw std::bad_alloc();
dbfp = dbfp->dbf_next;
}
if (dbfp) {

View File

@ -976,7 +976,7 @@ void PAG_header(const TEXT* file_name, USHORT file_length)
and unit of transfer is a multiple of physical disk
sector for raw disk access. */
SCHAR* const temp_buffer = (SCHAR*)gds__alloc((SLONG) 2 * MIN_PAGE_SIZE);
SCHAR* const temp_buffer = FB_NEW(*getDefaultMemoryPool()) SCHAR[2 * MIN_PAGE_SIZE];
SCHAR* temp_page =
(SCHAR *) (((U_IPTR) temp_buffer + MIN_PAGE_SIZE - 1) &
~((U_IPTR) MIN_PAGE_SIZE - 1));
@ -1112,12 +1112,11 @@ if (header->hdr_implementation && header->hdr_implementation != CLASS)
}
if (temp_buffer)
gds__free(temp_buffer);
delete[] temp_buffer;
} // try
catch (const std::exception&) {
if (temp_buffer) {
gds__free(temp_buffer);
}
if (temp_buffer)
delete[] temp_buffer;
throw;
}
}
@ -1213,8 +1212,7 @@ void PAG_init2(USHORT shadow_number)
and set up to release it in case of error. Align
the temporary page buffer for raw disk access. */
SCHAR* const temp_buffer =
(SCHAR*) gds__alloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
SCHAR* const temp_buffer = FB_NEW(*getDefaultMemoryPool()) SCHAR[dbb->dbb_page_size + MIN_PAGE_SIZE];
SCHAR* temp_page =
(SCHAR *) (((U_IPTR) temp_buffer + MIN_PAGE_SIZE - 1) &
~((U_IPTR) MIN_PAGE_SIZE - 1));
@ -1340,14 +1338,12 @@ void PAG_init2(USHORT shadow_number)
file->fil_sequence = sequence++;
}
if (temp_buffer) {
gds__free(temp_buffer);
}
if (temp_buffer)
delete[] temp_buffer;
} // try
catch (const std::exception&) {
if (temp_buffer) {
gds__free(temp_buffer);
}
if (temp_buffer)
delete[] temp_buffer;
throw;
}
}

View File

@ -222,6 +222,14 @@ bool SecurityDatabase::prepare()
if (!ihandle)
{
ihandle = (ihndl*) gds__alloc ((SLONG) sizeof(struct ihndl));
if (!ihandle)
{
THREAD_EXIT;
status[0] = isc_arg_gds;
status[1] = isc_virmemexh;
status[2] = isc_arg_end;
return false;
}
ihandle->ihndl_object = &lookup_db;
ihandle->ihndl_next = internal_db_handles;
internal_db_handles = ihandle;

View File

@ -20,7 +20,7 @@
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
* $Id: rse.cpp,v 1.57 2004-03-07 11:52:05 alexpeshkoff Exp $
* $Id: rse.cpp,v 1.58 2004-03-09 00:17:02 skidder Exp $
*
* 2001.07.28: John Bellardo: Implemented rse_skip and made rse_first work with
* seekable streams.
@ -942,14 +942,14 @@ static void close_merge(TDBB tdbb, Rsb* rsb, IRSB_MRG impure)
if (sfb->sfb_file_name) {
close(sfb->sfb_file);
unlink(sfb->sfb_file_name);
gds__free(sfb->sfb_file_name);
delete[] sfb->sfb_file_name;
}
delete sfb->sfb_mem;
delete sfb;
mfb->mfb_sfb = 0;
}
if (mfb->mfb_block_data) {
gds__free(mfb->mfb_block_data);
delete[] mfb->mfb_block_data;
mfb->mfb_block_data = 0;
}
}
@ -1750,7 +1750,7 @@ static BOOLEAN get_merge_join(
MFB mfb = &tail->irsb_mrg_file;
const ULONG key_length = map->smb_key_length * sizeof(ULONG);
if (key_length > sizeof(key))
first_data = (UCHAR *) gds__alloc(key_length);
first_data = FB_NEW(*tdbb->tdbb_default) [key_length];
else
first_data = (UCHAR *) key;
MOVE_FASTER(get_merge_data(tdbb, mfb, 0), first_data, key_length);
@ -1769,7 +1769,7 @@ static BOOLEAN get_merge_join(
}
if (first_data != (UCHAR *) key)
gds__free(first_data);
delete[] first_data;
if (mfb->mfb_current_block)
write_merge_block(tdbb, mfb, mfb->mfb_current_block);
}
@ -1943,7 +1943,7 @@ static BOOLEAN get_merge_join(TDBB tdbb, Rsb* rsb, IRSB_MRG impure)
mfb = &tail->irsb_mrg_file;
key_length = map->smb_key_length * sizeof(ULONG);
if (key_length > sizeof(key))
first_data = (UCHAR *) gds__alloc(key_length);
first_data = FB_NEW(*tdbb->tdbb_default) UCHAR[key_length];
else
first_data = (UCHAR *) key;
MOVE_FASTER(get_merge_data(tdbb, mfb, 0), first_data, key_length);
@ -1962,7 +1962,7 @@ static BOOLEAN get_merge_join(TDBB tdbb, Rsb* rsb, IRSB_MRG impure)
}
if (first_data != (UCHAR *) key)
gds__free(first_data);
delete[] first_data;
if (mfb->mfb_current_block)
write_merge_block(tdbb, mfb, mfb->mfb_current_block);
}
@ -3025,8 +3025,8 @@ static void open_merge(TDBB tdbb, Rsb* rsb, IRSB_MRG impure)
mfb->mfb_block_size = MAX(mfb->mfb_record_size, MERGE_BLOCK_SIZE);
mfb->mfb_blocking_factor = mfb->mfb_block_size / mfb->mfb_record_size;
if (!mfb->mfb_block_data)
mfb->mfb_block_data =
reinterpret_cast<UCHAR*>(gds__alloc(mfb->mfb_block_size));
mfb->mfb_block_data =
FB_NEW(*tdbb->tdbb_request->req_pool) UCHAR[mfb->mfb_block_size];
}
}
@ -3789,8 +3789,8 @@ static void write_merge_block(TDBB tdbb, MFB mfb, ULONG block)
if (sfb_->sfb_file == -1)
SORT_error(tdbb->tdbb_status_vector, sfb_, "open", isc_io_error,
errno);
sfb_->sfb_file_name = (SCHAR*)
gds__alloc((ULONG) (strlen(file_name) + 1));
sfb_->sfb_file_name =
FB_NEW(*getDefaultMemoryPool()) char[strlen(file_name) + 1];
strcpy(sfb_->sfb_file_name, file_name);
sfb_->sfb_mem = FB_NEW (*getDefaultMemoryPool()) SortMem(sfb_, mfb->mfb_block_size);

View File

@ -175,8 +175,8 @@ int SDW_add_file(const TEXT* file_name, SLONG start, USHORT shadow_number)
and set up to release it in case of error. Align
the spare page buffer for raw disk access. */
SCHAR* const spare_buffer = (SCHAR*)
gds__alloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
SCHAR* const spare_buffer =
FB_NEW(*tdbb->tdbb_default) char[dbb->dbb_page_size + MIN_PAGE_SIZE];
// And why doesn't the code check that the allocation succeeds?
SCHAR* spare_page =
@ -206,9 +206,8 @@ int SDW_add_file(const TEXT* file_name, SLONG start, USHORT shadow_number)
reinterpret_cast<pag*>(header),
0))
{
if (spare_buffer) {
gds__free(spare_buffer);
}
if (spare_buffer)
delete[] spare_buffer;
return 0;
}
next->fil_fudge = 1;
@ -254,9 +253,8 @@ else
reinterpret_cast<pag*>(header),
0))
{
if (spare_buffer) {
gds__free(spare_buffer);
}
if (spare_buffer)
delete[] spare_buffer;
return 0;
}
if (file->fil_min_page) {
@ -268,15 +266,13 @@ else
file->fil_fudge = 1;
}
if (spare_buffer) {
gds__free(spare_buffer);
}
if (spare_buffer)
delete[] spare_buffer;
} // try
catch (const std::exception&) {
if (spare_buffer) {
gds__free(spare_buffer);
}
if (spare_buffer)
delete[] spare_buffer;
throw;
}
@ -947,7 +943,7 @@ void SDW_start(
shadow = NULL;
SLONG* const spare_buffer =
(SLONG *) gds__alloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
FB_NEW(*tdbb->tdbb_default) SLONG[(dbb->dbb_page_size + MIN_PAGE_SIZE)/sizeof(SLONG)];
SLONG* spare_page = reinterpret_cast<SLONG*>((SCHAR *)
(((U_IPTR)
spare_buffer + MIN_PAGE_SIZE -
@ -1041,9 +1037,8 @@ void SDW_start(
/* get the ancillary files and reset the error environment */
PAG_init2(shadow_number);
if (spare_buffer) {
gds__free(spare_buffer);
}
if (spare_buffer)
delete[] spare_buffer;
} // try
catch (const std::exception& ex) {
@ -1055,9 +1050,8 @@ void SDW_start(
PIO_close(shadow_file);
delete shadow_file;
}
if (spare_buffer) {
gds__free(spare_buffer);
}
if (spare_buffer)
delete[] spare_buffer;
if (file_flags & FILE_manual && !delete_) {
ERR_post(isc_shadow_missing, isc_arg_number,
(SLONG) shadow_number, 0);

View File

@ -19,7 +19,7 @@
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
* $Id: sort.cpp,v 1.54 2004-02-20 06:43:00 robocop Exp $
* $Id: sort.cpp,v 1.55 2004-03-09 00:17:03 skidder Exp $
*
* 2001-09-24 SJL - Temporary fix for large sort file bug
*
@ -733,9 +733,8 @@ SCB SORT_init(ISC_STATUS* status_vector,
// key description vector. Round the record length up to the next
// longword, and add a longword to a pointer back to the pointer slot.
try {
scb = (SCB) gds__alloc((SLONG) SCB_LEN(keys));
} catch(const std::exception&) {
scb = (SCB) gds__alloc((SLONG) SCB_LEN(keys));
if (!scb) {
// FREE: scb is freed by SORT_fini(), called by higher level cleanup
// FREE: or later in this module in error cases
*status_vector++ = isc_arg_gds;
@ -766,28 +765,27 @@ SCB SORT_init(ISC_STATUS* status_vector,
ROUNDUP(p->skd_offset + p->skd_length, sizeof(SLONG)) >> SHIFTLONG;
// Next, try to allocate a "big block". How big? Big enough!
try {
#ifdef DEBUG_MERGE
// To debug the merge algorithm, force the in-memory pool to be VERY small
scb->scb_size_memory = 2000;
scb->scb_memory =
(SORTP *) gds__alloc((SLONG) scb->scb_size_memory);
// FREE: scb_memory is freed by local_fini()
// To debug the merge algorithm, force the in-memory pool to be VERY small
scb->scb_size_memory = 2000;
scb->scb_memory =
(SORTP *) gds__alloc((SLONG) scb->scb_size_memory);
// FREE: scb_memory is freed by local_fini()
#else
// Try to get a big chunk of memory, if we can't try smaller and
// smaller chunks until we can get the memory. If we get down to
// too small a chunk - punt and report not enough memory.
// Try to get a big chunk of memory, if we can't try smaller and
// smaller chunks until we can get the memory. If we get down to
// too small a chunk - punt and report not enough memory.
for (scb->scb_size_memory = MAX_SORT_BUFFER_SIZE;;
scb->scb_size_memory -= SORT_BUFFER_CHUNK_SIZE)
if (scb->scb_size_memory < MIN_SORT_BUFFER_SIZE)
break;
else if ( (scb->scb_memory =
(SORTP *) gds__alloc((SLONG) scb->scb_size_memory)) )
// FREE: scb_memory is freed by local_fini()
break;
for (scb->scb_size_memory = MAX_SORT_BUFFER_SIZE;;
scb->scb_size_memory -= SORT_BUFFER_CHUNK_SIZE)
if (scb->scb_size_memory < MIN_SORT_BUFFER_SIZE)
break;
else if ( (scb->scb_memory =
(SORTP *) gds__alloc((SLONG) scb->scb_size_memory)) )
// FREE: scb_memory is freed by local_fini()
break;
#endif // DEBUG_MERGE
} catch(const std::exception&) {
if (!scb->scb_memory) {
*status_vector++ = isc_arg_gds;
*status_vector++ = isc_sort_mem_err; // Msg356: sort error: not enough memory
*status_vector = isc_arg_end;
@ -1052,14 +1050,13 @@ bool SORT_sort(ISC_STATUS * status_vector, SCB scb)
++run_count;
}
try {
if ((run_count * sizeof(RMH)) > sizeof(streams_local))
streams =
(RMH *) gds__alloc((SLONG) run_count * sizeof(RMH));
// FREE: streams is freed later in this routine
else
streams = streams_local;
} catch(const std::exception&) {
if ((run_count * sizeof(RMH)) > sizeof(streams_local))
streams =
(RMH *) gds__alloc((SLONG) run_count * sizeof(RMH));
// FREE: streams is freed later in this routine
else
streams = streams_local;
if (!streams) {
*status_vector++ = isc_arg_gds;
*status_vector++ = isc_sort_mem_err;
*status_vector = isc_arg_end;
@ -1076,12 +1073,11 @@ bool SORT_sort(ISC_STATUS * status_vector, SCB scb)
if (count > 1) {
fb_assert(!scb->scb_merge_pool); // shouldn't have a pool
try {
scb->scb_merge_pool =
(MRG) gds__alloc((SLONG) (count - 1)*sizeof(struct mrg));
// FREE: smb_merge_pool freed in local_fini() when the scb is released
merge_pool = scb->scb_merge_pool;
} catch(const std::exception&) {
scb->scb_merge_pool =
(MRG) gds__alloc((SLONG) (count - 1)*sizeof(struct mrg));
// FREE: smb_merge_pool freed in local_fini() when the scb is released
merge_pool = scb->scb_merge_pool;
if(!merge_pool) {
gds__free(streams);
*status_vector++ = isc_arg_gds;
*status_vector++ = isc_sort_mem_err;
@ -1171,11 +1167,10 @@ bool SORT_sort(ISC_STATUS * status_vector, SCB scb)
// allocating enough for the merge space plus a link
for (; run; run = run->run_next) {
try {
run->run_buffer =
(ULONG *) gds__alloc((SLONG) (size * sizeof(ULONG)));
// FREE: smb_merge_space freed in local_fini() when the scb is released
} catch(const std::exception&) {
run->run_buffer =
(ULONG *) gds__alloc((SLONG) (size * sizeof(ULONG)));
// FREE: smb_merge_space freed in local_fini() when the scb is released
if (!run->run_buffer) {
*status_vector++ = isc_arg_gds;
*status_vector++ = isc_sort_mem_err;
*status_vector = isc_arg_end;
@ -1293,16 +1288,13 @@ static UCHAR *sort_alloc(SCB scb, ULONG size)
**************************************/
UCHAR* block = 0;
try {
block =
reinterpret_cast<UCHAR*>(gds__alloc(size));
// FREE: caller responsible for freeing
} catch(const std::exception&) {
if (!block)
{
error_memory(scb);
return NULL;
}
block =
reinterpret_cast<UCHAR*>(gds__alloc(size));
// FREE: caller responsible for freeing
if (!block)
{
error_memory(scb);
return NULL;
}
memset(block, 0, size);
@ -1779,7 +1771,7 @@ static ULONG find_file_space(SCB scb, ULONG size, SFB * ret_sfb)
// This is released during local_fini()
sfb->sfb_file_name =
(TEXT *) sort_alloc(scb, (ULONG) (strlen(file_name) + 1));
FB_NEW(*getDefaultMemoryPool()) char[strlen(file_name) + 1];
// FREE: sfb_file_name is freed in local_fini()
strcpy(sfb->sfb_file_name, file_name);
@ -2218,7 +2210,7 @@ static bool local_fini(SCB scb, ATT att)
close(sfb->sfb_file);
if (sfb->sfb_file_name) {
gds__free(sfb->sfb_file_name);
delete[] sfb->sfb_file_name;
sfb->sfb_file_name = NULL;
}
@ -2332,14 +2324,11 @@ static void merge_runs(SCB scb, USHORT n)
if (!size) {
if (!run->run_buff_alloc) {
try {
run->run_buffer =
(ULONG *) gds__alloc((SLONG) rec_size * 2);
} catch (const std::exception&) {
// FREE: smb_merge_space freed in local_fini() when scb released
if (!run->run_buffer)
error_memory(scb);
}
run->run_buffer =
(ULONG *) gds__alloc((SLONG) rec_size * 2);
// FREE: smb_merge_space freed in local_fini() when scb released
if (!run->run_buffer)
error_memory(scb);
run->run_buff_alloc = 1;
}
run->run_end_buffer =
@ -2660,17 +2649,15 @@ static ULONG order(SCB scb)
lower_limit =
reinterpret_cast<SORT_PTR*>(output = reinterpret_cast<sort_record*>(scb->scb_last_record));
try {
if ((scb->scb_longs * sizeof(ULONG)) > sizeof(temp))
buffer =
(ULONG *) gds__alloc((SLONG) (scb->scb_longs*sizeof(ULONG)));
// FREE: buffer is freed later in this routine
else
buffer = temp;
} catch(const std::exception&) {
if (!buffer)
error_memory(scb);
}
if (!buffer)
error_memory(scb);
// Check out the engine

View File

@ -61,13 +61,13 @@ SortMem::MemoryBlock::MemoryBlock(Block* tail, size_t length)
: Block(tail, length)
{
// Allocate virtual memory block
address = reinterpret_cast<char*>(gds__alloc(size));
address = FB_NEW(*getDefaultMemoryPool()) char[size];
}
SortMem::MemoryBlock::~MemoryBlock()
{
// Free virtual memory block
gds__free(address);
delete[] address;
}
size_t SortMem::MemoryBlock::read(ISC_STATUS *status, size_t position, char *buffer, size_t length)

View File

@ -479,6 +479,7 @@ svc* SVC_attach(USHORT service_length,
USHORT param_length = sizeof(SERVICE_THD_PARAM) - 1;
USHORT spb_buf_length = spb_length + param_length - ignored_length + 1;
SCHAR* q = spb_buf = (TEXT*) gds__alloc(spb_buf_length + 1);
if(!q) ERR_post(isc_virmemexh, 0);
memcpy(q, spb, p - spb);
q += p - spb - 1;
*q++ += param_length - ignored_length + 1;

View File

@ -2727,6 +2727,11 @@ static void THREAD_ROUTINE sweep_database(char* database)
if (!ihandle)
{
ihandle = (ihndl*) gds__alloc ((SLONG) sizeof (struct ihndl));
if (!ihandle) {
THREAD_EXIT;
ERR_log(0, 0, "cannot start sweep thread: out of memory");
return;
}
ihandle->ihndl_object = &db_handle;
ihandle->ihndl_next = internal_db_handles;
internal_db_handles = ihandle;

View File

@ -42,7 +42,7 @@
*
*/
/*
$Id: why.cpp,v 1.56 2004-03-07 07:58:42 robocop Exp $
$Id: why.cpp,v 1.57 2004-03-09 00:17:03 skidder Exp $
*/
#include "firebird.h"
@ -5413,15 +5413,13 @@ static const PTR get_entrypoint(int proc,
if (image && name)
{
#define BufSize 128
#define BufSize 128
TEXT Buffer[BufSize];
SLONG NameLength = strlen(name) + 1;
TEXT *NamePointer = NameLength > BufSize ?
reinterpret_cast<TEXT *>(gds__alloc(NameLength)) : Buffer;
fb_assert(NameLength < BufSize);
TEXT *NamePointer = Buffer;
memcpy(NamePointer, name, NameLength);
PTR entry = (PTR) ISC_lookup_entrypoint(image, NamePointer, NULL, false);
if (NameLength > BufSize)
gds__free(NamePointer);
if (entry)
{
// This const_cast appears to be safe, because:

View File

@ -599,6 +599,10 @@ static char* alloc( SLONG size)
*
**************************************/
char* const block = (char*) gds__alloc(size);
if (!block) {
/* NOMEM: return error */
dba_error(31, 0, 0, 0, 0, 0);
}
char* p = block;
do {
*p++ = 0;

View File

@ -32,7 +32,7 @@
* Contributor(s):
*
*
* $Id: nbackup.cpp,v 1.14 2004-02-20 06:43:20 robocop Exp $
* $Id: nbackup.cpp,v 1.15 2004-03-09 00:17:05 skidder Exp $
*
*/
@ -107,11 +107,7 @@ public:
char temp[1024];
va_list params;
va_start(params, message);
#ifdef HAVE_VSNPRINTF
vsnprintf(temp, sizeof(temp), message, params);
#else
vsprintf(temp, message, params);
#endif
VSNPRINTF(temp, sizeof(temp), message, params);
fprintf(stderr, "Failure: %s\n", temp);
va_end(params);
throw b_error(temp);