valgrind memcheck: fix small pool memory leaks in the unittests.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent dbe2a86ffe
commit c5b2b8c082

@ -210,12 +210,13 @@ end:
static int PoolTestInit03 (void) { static int PoolTestInit03 (void) {
int retval = 0; int retval = 0;
void *data = NULL;
Pool *p = PoolInit(10,5,PoolTestAlloc,NULL,PoolTestFree); Pool *p = PoolInit(10,5,PoolTestAlloc,NULL,PoolTestFree);
if (p == NULL) if (p == NULL)
goto end; goto end;
void *data = PoolGet(p); data = PoolGet(p);
if (data == NULL) { if (data == NULL) {
printf("PoolGet returned NULL: "); printf("PoolGet returned NULL: ");
retval = 0; retval = 0;
@ -236,6 +237,8 @@ static int PoolTestInit03 (void) {
retval = 1; retval = 1;
end: end:
if (data != NULL)
free(data);
if (p != NULL) if (p != NULL)
PoolFree(p); PoolFree(p);
return retval; return retval;
@ -243,12 +246,13 @@ end:
static int PoolTestInit04 (void) { static int PoolTestInit04 (void) {
int retval = 0; int retval = 0;
char *str = NULL;
Pool *p = PoolInit(10,5,PoolTestAllocArg,(void *)"test",PoolTestFree); Pool *p = PoolInit(10,5,PoolTestAllocArg,(void *)"test",PoolTestFree);
if (p == NULL) if (p == NULL)
goto end; goto end;
char *str = PoolGet(p); str = PoolGet(p);
if (str == NULL) { if (str == NULL) {
printf("PoolGet returned NULL: "); printf("PoolGet returned NULL: ");
retval = 0; retval = 0;
@ -275,6 +279,8 @@ static int PoolTestInit04 (void) {
retval = 1; retval = 1;
end: end:
if (str != NULL)
free(str);
if (p != NULL) if (p != NULL)
PoolFree(p); PoolFree(p);
return retval; return retval;
@ -282,12 +288,13 @@ end:
static int PoolTestInit05 (void) { static int PoolTestInit05 (void) {
int retval = 0; int retval = 0;
void *data = NULL;
Pool *p = PoolInit(10,5,PoolTestAlloc,NULL,PoolTestFree); Pool *p = PoolInit(10,5,PoolTestAlloc,NULL,PoolTestFree);
if (p == NULL) if (p == NULL)
goto end; goto end;
void *data = PoolGet(p); data = PoolGet(p);
if (data == NULL) { if (data == NULL) {
printf("PoolGet returned NULL: "); printf("PoolGet returned NULL: ");
retval = 0; retval = 0;
@ -323,6 +330,8 @@ static int PoolTestInit05 (void) {
retval = 1; retval = 1;
end: end:
if (data != NULL)
free(data);
if (p != NULL) if (p != NULL)
PoolFree(p); PoolFree(p);
return retval; return retval;
@ -331,6 +340,7 @@ end:
static int PoolTestInit06 (void) { static int PoolTestInit06 (void) {
int retval = 0; int retval = 0;
void *data = NULL; void *data = NULL;
void *data2 = NULL;
Pool *p = PoolInit(1,0,PoolTestAlloc,NULL,PoolTestFree); Pool *p = PoolInit(1,0,PoolTestAlloc,NULL,PoolTestFree);
if (p == NULL) if (p == NULL)
@ -355,9 +365,9 @@ static int PoolTestInit06 (void) {
goto end; goto end;
} }
data = PoolGet(p); data2 = PoolGet(p);
if (data != NULL) { if (data2 != NULL) {
printf("PoolGet returned %p, expected NULL: ", data); printf("PoolGet returned %p, expected NULL: ", data2);
retval = 0; retval = 0;
goto end; goto end;
} }
@ -381,6 +391,8 @@ static int PoolTestInit06 (void) {
end: end:
if (data != NULL) if (data != NULL)
free(data); free(data);
if (data2 != NULL)
free(data2);
if (p != NULL) if (p != NULL)
PoolFree(p); PoolFree(p);
return retval; return retval;

Loading…
Cancel
Save