Opened 19 years ago
Closed 19 years ago
#845 closed defect (worksforme)
psHashAdd stomps on memory
| Reported by: | eugene | Owned by: | Paul Price |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | astro | Version: | 0.12.99 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
psHashAdd is supposed to free the existing item of the same name, but does not:
psHash *hash = psHashAlloc(16);
psHashAdd (hash, "name", item);
psMemId id = psMemGetId();
psHashAdd (hash, "name", item);
psMemCheckLeaks (id, NULL, NULL, false);
this will claim a leak exists.
Note:
See TracTickets
for help on using tickets.

The code will rightly report that a leak exists in the snippet, since the
references haven't been dropped at the top level. An inspection of the psHash
code reveals the correct behaviour (free the existing pointer before adding the
new one). When the references are dropped by the user, there are no memory leaks.
#include <stdio.h>
#include "pslib.h"
#include "pstap.h"
#define SIZE 128
int main(int argc, char *argv[])
{
}
price@mithrandir:/home/mithrandir/price/mhpcc/psLib/test/types>./tap_psHash_845 1..5
ok 1 - Hash allocated
ok 2 - Added 1 to hash
ok 3 - Added 2 to hash
ok 4 - No leaks.
ok 5 - Memory Leaks