// test overwritten data with bfreef() int main() { static char sarr[SARRSIZ]; char *sarr_ptr = __ptralign(sarr,HSIZE) + HSIZE; // new pointer char *str = mallocf(STRSIZ); int i; strncpy(str, "This is a test.", STRSIZ); str[STRSIZ-1] = '\0'; strncpy(sarr, "This is data from a static array.", SARRSIZ); sarr[SARRSIZ-1] = '\0'; printf("str = %s\n", str); printf("sarr position = %p (%s)\n", sarr, (unsigned long)sarr%HSIZE ? "unaligned" : "aligned"); printf("sarr = %s\n", sarr); bfreef(sarr, SARRSIZ); freef(str); printf("sarr = %s\n", sarr); printf("sarr_ptr position = %p\n", sarr_ptr); printf("sarr =\n"); for (i=0; i<SARRSIZ; ++i) printf("0x%02x%c", (unsigned char) sarr[i], (i+1)*5%80 ?' ' : '\n'); while (str != sarr_ptr) // assumption is that sarr size % 16 == 0 str = mallocf(SARRSIZ-HSIZE); // egregious memory leak printf("found str = sarr_ptr\n"); strncpy(str, "This is data that overwrites static data.", SARRSIZ-HSIZE); str[SARRSIZ-HSIZE-1] = '\0'; printf("str = %s\n", str); printf("sarr =\n"); for (i=0; i<SARRSIZ; ++i) printf("0x%02x%c", (unsigned char) sarr[i], (i+1)*5%80 ?' ' : '\n'); freef(str); return 0; }
int main(void) { int width = 2560; int height = 1440; int i; int frames = 200; char fpath[100]; char **grid; /* init */ grid = allocf(width, height); double scale = 50.0; double offset = 1.0; double offset2 = 1.0; double offset3 = 1.0; double offset4 = 1.0; for (i = 0; i < frames; i++) { snprintf(fpath, 100, "plt_pbm_%05d.pbm", i); FILE *pbmf = fopen(fpath, "w"); clearf(grid, width, height); draw_sin(grid, width, height, scale, offset); draw_cos(grid, width, height, scale, offset2); draw_sin(grid, width, height, scale, offset3); draw_cos(grid, width, height, scale, offset4); offset += 0.09; offset2 += 0.11; offset3 += 0.13; offset4 += 0.16; pbmgrid(grid, width, height, pbmf); fclose(pbmf); fprintf(stderr, "i: %d\n", i); } /* clean up */ freef(grid, width); return 0; }
void hash_free(hashp h, void (*freef)( )) { hashindex *o, *f; int i; for (i = 0; i < 27; i++) { o = h->list[i]; while(o != NULL) { f = o; o = o->next; free(f->data); if(freef != NULL) freef(f->info); free(f); } h->list[i] = NULL; } }