Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 2f0b7fe

Browse files
committed
[CID 16735] revdb: Prevent possible memory leak in BindVariables
There's not point in allocating a buffer with `malloc()` if it's not going to get used. Coverity-ID: 16735
1 parent 5b565c1 commit 2f0b7fe

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

revdb/src/revdb.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,15 +660,15 @@ DBString *BindVariables(char *p_arguments[],int p_argument_count, int &r_value_c
660660
free(t_variable_name);
661661
free(t_key_name);
662662

663-
// OK-2008-12-09: Because the engine retains ownership of t_value . buffer, using it can lead
664-
// to problems where the engine overwrites the buffer, leading to the wrong values being
665-
// inserted into databases. The problem is fixed by creating duplicates of any buffers returned.
666-
char *t_new_buffer;
667-
t_new_buffer = (char *)malloc(t_value . length);
668-
memcpy(t_new_buffer, t_value . buffer, t_value . length);
669-
670663
if (t_value . buffer != NULL)
671664
{
665+
// OK-2008-12-09: Because the engine retains ownership of t_value . buffer, using it can lead
666+
// to problems where the engine overwrites the buffer, leading to the wrong values being
667+
// inserted into databases. The problem is fixed by creating duplicates of any buffers returned.
668+
char *t_new_buffer;
669+
t_new_buffer = (char *)malloc(t_value . length);
670+
memcpy(t_new_buffer, t_value . buffer, t_value . length);
671+
672672
t_values[r_value_count] . Set(t_new_buffer, t_value . length, t_is_binary);
673673
r_value_count += 1;
674674
}

0 commit comments

Comments
 (0)