Skip to content

Commit 98fd42f

Browse files
author
Igor Solodovnikov
committed
Bug #16591288 WINAUTH PLUGIN LEAKS MEMORY AFTER EACH CONNECTION
Memory leak was caused by Security_buffer helper class. Its free() method was implemented to set m_allocated=false after freeing context buffer. Since Security_buffer has no means to set m_allocated back to true this leads to not freeing all subsequent context buffers. Fixed by: - making Security_buffer::m_allocated const object (so it can be assigned by constructor only) - rewriting Security_buffer::free() to not alter value of Security_buffer::m_allocated - Disallow copying/assignment of Security_buffer class instances to prevent new memory leaks in the future This patch also fixes minor bugs in Map_cache class.
1 parent 5c2b61d commit 98fd42f

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

libmysql/authentication_win/handshake.cc

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -280,10 +280,9 @@ Security_buffer::Security_buffer(): m_allocated(true)
280280

281281
void Security_buffer::free(void)
282282
{
283-
if (!m_allocated)
284-
return;
285-
if (!ptr())
286-
return;
287-
FreeContextBuffer(ptr());
288-
m_allocated= false;
283+
if (m_allocated && NULL != ptr())
284+
{
285+
FreeContextBuffer(ptr());
286+
init(NULL, 0);
287+
}
289288
}

libmysql/authentication_win/handshake.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -53,7 +53,12 @@ class Security_buffer: public SecBufferDesc
5353
}
5454

5555
/// If @c false, no deallocation will be done in the destructor.
56-
bool m_allocated;
56+
const bool m_allocated;
57+
58+
// Copying/assignment is not supported and can lead to memory leaks
59+
// So declaring copy constructor and assignment operator as private
60+
Security_buffer( const Security_buffer& );
61+
const Security_buffer& operator=( const Security_buffer& );
5762

5863
public:
5964

@@ -75,11 +80,6 @@ class Security_buffer: public SecBufferDesc
7580
return m_buf.cbBuffer;
7681
}
7782

78-
bool is_valid() const
79-
{
80-
return ptr() != NULL;
81-
}
82-
8383
const Blob as_blob() const
8484
{
8585
return Blob(ptr(), len());

0 commit comments

Comments
 (0)