Skip to content

Commit

Permalink
Upmerge branch 'upstream/candidate-1.2.0' into candidate-1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jamienoss committed May 20, 2017
2 parents f5bc82a + 5998905 commit 5d82a4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions hstio/hstio.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ void addPtr(PtrRegister * reg, void * ptr, void * freeFunc)
if (++reg->cursor >= reg->length)
{
reg->length += PTR_REGISTER_LENGTH_INC;
assert(realloc(&reg->ptrs, reg->length*sizeof(*reg->ptrs)));
assert(realloc(reg->freeFunctions, reg->length*sizeof(*reg->freeFunctions)));
assert(reg->ptrs = realloc(reg->ptrs, reg->length*sizeof(*reg->ptrs)));
assert(reg->freeFunctions = realloc(reg->freeFunctions, reg->length*sizeof(*reg->freeFunctions)));
}
reg->ptrs[reg->cursor] = ptr;
reg->freeFunctions[reg->cursor] = freeFunc;
Expand Down Expand Up @@ -208,19 +208,24 @@ void freeAll(PtrRegister * reg)
}
void freeReg(PtrRegister * reg)
{
/* THIS SHOULD NEVER CALL freeALL()
* This is designed to be used when allocating multiple persistent memory allocations,
* registering each allocation in turn. If one allocation fails freeOnExit() can be
* called to free prior successful allocations and if all allocations are successful
* this function can be called to free the registers without freeing the actual
* pointers just allocated.
*/

if (!reg || reg->length == 0)
return;

if (reg->cursor > 0)
freeAll(reg);

reg->cursor = 0;
reg->length = 0;
// free 'itself'
reg->freeFunctions[0](reg->ptrs);
reg->ptrs[0] = NULL;
reg->freeFunctions[0](reg->freeFunctions);
reg->freeFunctions[0] = NULL;
free(reg->ptrs);
reg->ptrs = NULL;
free(reg->freeFunctions);
reg->freeFunctions = NULL;
}
void freeOnExit(PtrRegister * reg)
{
Expand Down
2 changes: 1 addition & 1 deletion include/hstio.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void addPtr(PtrRegister * reg, void * ptr, void * freeFunc); // ptr list is self
void freePtr(PtrRegister * reg, void * ptr);
void freeOnExit(PtrRegister * reg); //only calls freeAll() followed by freeReg()
void freeAll(PtrRegister * reg); // frees all ptrs registered (excluding itself)
void freeReg(PtrRegister * reg); // frees itself i.e. the register array holding the ptrs
void freeReg(PtrRegister * reg); //frees ONLY the registers themselves and NOT the pointers in PtrRegister::ptrs

# define SZ_PATHNAME 511

Expand Down

0 comments on commit 5d82a4e

Please sign in to comment.