Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25852] Add freemem() in cubmem::block to simplify deleting memory routines #5835

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/base/mem_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ namespace cubmem

inline bool is_valid () const;

inline void freemem ();

inline char *move_ptr (); //NOT RECOMMENDED! use move semantics: std::move()

private:
Expand Down Expand Up @@ -269,6 +271,17 @@ namespace cubmem
return (dim != 0 && ptr != NULL);
}

void
block::freemem ()
{
if (is_valid ())
{
delete[] ptr;
dim = 0;
ptr = NULL;
}
}

char *
block::move_ptr ()
{
Expand Down
9 changes: 2 additions & 7 deletions src/sp/pl_compile_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,8 @@ namespace cubpl
m_stack->get_data_queue ().pop ();
}

// free phase
if (response_blk.is_valid ())
{
delete [] response_blk.ptr;
response_blk.ptr = NULL;
response_blk.dim = 0;
}
// free reponse block
response_blk.freemem ();
}
while (error_code == NO_ERROR && code != METHOD_REQUEST_COMPILE);

Expand Down
8 changes: 2 additions & 6 deletions src/sp/pl_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,8 @@ namespace cubpl
{
cubmem::block b = pack_data_block (std::forward<Args> (args)...);
int status = send_buffer (b);
if (b.is_valid ())
{
delete [] b.ptr;
b.ptr = NULL;
b.dim = 0;
}
b.freemem ();

return status;
}

Expand Down
25 changes: 5 additions & 20 deletions src/sp/pl_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,8 @@ namespace cubpl
m_stack->get_data_queue ().pop ();
}

// free phase
if (response_blk.is_valid ())
{
delete [] response_blk.ptr;
response_blk.ptr = NULL;
response_blk.dim = 0;
}
// free response block
response_blk.freemem ();
}
while (error_code == NO_ERROR && start_code == SP_CODE_INTERNAL_JDBC);

Expand Down Expand Up @@ -637,7 +632,7 @@ namespace cubpl
if (blk.is_valid ())
{
m_stack->send_data_to_java (blk);
delete[] blk.ptr;
blk.freemem ();
}

return error;
Expand Down Expand Up @@ -802,13 +797,7 @@ namespace cubpl
}

error = m_stack->send_data_to_java (blk);
if (blk.is_valid ())
{
delete [] blk.ptr;
blk.ptr = NULL;
blk.dim = 0;
}

blk.freemem ();
return error;
}

Expand Down Expand Up @@ -1026,11 +1015,7 @@ namespace cubpl
db_value_clear (&res);

error = m_stack->send_data_to_java (blk);

if (blk.is_valid ())
{
delete[] blk.ptr;
}
blk.freemem ();

return error;
}
Expand Down
9 changes: 3 additions & 6 deletions src/sp/pl_sr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,7 @@ namespace cubpl
}

exit:
if (ping_response.is_valid ())
{
delete [] ping_response.ptr;
ping_response.ptr = NULL;
ping_response.dim = 0;
}
ping_response.freemem ();

cv.reset ();

Expand Down Expand Up @@ -605,6 +600,8 @@ namespace cubpl
{
packing_unpacker deserializator (bootstrap_response);
deserializator.unpack_int (error);

bootstrap_response.freemem ();
}

return error;
Expand Down
Loading