Bug #1634 "operator new" in my_new wastes memory

Submitted: 23 Oct 2003 2:03 Modified: 30 Oct 2003 1:30
Reporter: Marko Mäkelä Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0 and 4.1 OS:Linux (GNU/Linux)
Assigned to: Konstantin Osipov CPU Architecture:Any

[23 Oct 2003 2:03] Marko Mäkelä
Description:
Here's a snip from mysys/my_new.cc.

void *operator new (size_t sz)
{
  return (void *) malloc (sz ? sz+1 : sz);
}

void *operator new[] (size_t sz)
{
  return (void *) malloc (sz ? sz+1 : sz);
}

How to repeat:
Compile the code with -DUSE_MYSYS_NEW.  Try to allocate an object of size 0.  The argument of the malloc function will evaluate to 0, and the intended work-around for allocating zero bytes will fail.  Try to allocate an object of any other size.  The argument of malloc will evaluate to sz+1, wasting at least one byte of memory.

Suggested fix:
I believe that the two "return" lines should be as follows:
return (void *) malloc (sz > 0 ? sz : 1);
[30 Oct 2003 1:30] Konstantin Osipov
Fixed, ChangeSet 1.1601 03/10/30 12:25:15 konstantin@mysql.com

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.048 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.