From 30a449841cb28ab9e0b20bbe601ac4fc51fd33ab Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Thu, 27 Jun 2019 19:21:17 +0200 Subject: [PATCH] nbis: Use GLib memory management functions Apply the previously added spatch/coccinell file to replace all free/malloc/realloc calls with g_free/g_malloc/g_realloc. It also removes all the error code paths that we do not need to check anymore. This means that the returned data must be free'ed using g_free rather than free, making memory management more consistent. --- libfprint/nbis/mindtct/binar.c | 6 +- libfprint/nbis/mindtct/block.c | 6 +- libfprint/nbis/mindtct/chaincod.c | 7 +- libfprint/nbis/mindtct/contour.c | 45 ++------- libfprint/nbis/mindtct/detect.c | 80 +++++++-------- libfprint/nbis/mindtct/dft.c | 16 +-- libfprint/nbis/mindtct/free.c | 26 ++--- libfprint/nbis/mindtct/getmin.c | 22 ++-- libfprint/nbis/mindtct/imgutil.c | 14 +-- libfprint/nbis/mindtct/init.c | 161 ++++-------------------------- libfprint/nbis/mindtct/line.c | 17 +--- libfprint/nbis/mindtct/loop.c | 2 +- libfprint/nbis/mindtct/maps.c | 155 +++++++++++----------------- libfprint/nbis/mindtct/minutia.c | 105 +++++++------------ libfprint/nbis/mindtct/quality.c | 10 +- libfprint/nbis/mindtct/remove.c | 77 +++++++------- libfprint/nbis/mindtct/ridges.c | 69 +++++-------- libfprint/nbis/mindtct/shape.c | 56 ++--------- libfprint/nbis/mindtct/sort.c | 6 +- libfprint/nbis/mindtct/util.c | 21 +--- 20 files changed, 273 insertions(+), 628 deletions(-) diff --git a/libfprint/nbis/mindtct/binar.c b/libfprint/nbis/mindtct/binar.c index fb2be22..57c82a3 100644 --- a/libfprint/nbis/mindtct/binar.c +++ b/libfprint/nbis/mindtct/binar.c @@ -214,11 +214,7 @@ int binarize_image_V2(unsigned char **odata, int *ow, int *oh, bw = pw - (dirbingrids->pad<<1); bh = ph - (dirbingrids->pad<<1); - bdata = (unsigned char *)malloc(bw*bh*sizeof(unsigned char)); - if(bdata == (unsigned char *)NULL){ - fprintf(stderr, "ERROR : binarize_image_V2 : malloc : bdata\n"); - return(-600); - } + bdata = (unsigned char *)g_malloc(bw * bh * sizeof(unsigned char)); bptr = bdata; spptr = pdata + (dirbingrids->pad * pw) + dirbingrids->pad; diff --git a/libfprint/nbis/mindtct/block.c b/libfprint/nbis/mindtct/block.c index f530f94..ebdf8c3 100644 --- a/libfprint/nbis/mindtct/block.c +++ b/libfprint/nbis/mindtct/block.c @@ -134,11 +134,7 @@ int block_offsets(int **optr, int *ow, int *oh, lastbh = bh - 1; /* Allocate list of block offsets */ - blkoffs = (int *)malloc(bsize * sizeof(int)); - if(blkoffs == (int *)NULL){ - fprintf(stderr, "ERROR : block_offsets : malloc : blkoffs\n"); - return(-81); - } + blkoffs = (int *)g_malloc(bsize * sizeof(int)); /* Current block index */ bi = 0; diff --git a/libfprint/nbis/mindtct/chaincod.c b/libfprint/nbis/mindtct/chaincod.c index dd5d779..b5dd9ee 100644 --- a/libfprint/nbis/mindtct/chaincod.c +++ b/libfprint/nbis/mindtct/chaincod.c @@ -100,12 +100,7 @@ int chain_code_loop(int **ochain, int *onchain, /* number of points in the contour. There will be one chain code */ /* between each point on the contour including a code between the */ /* last to the first point on the contour (completing the loop). */ - chain = (int *)malloc(ncontour * sizeof(int)); - /* If the allocation fails ... */ - if(chain == (int *)NULL){ - fprintf(stderr, "ERROR : chain_code_loop : malloc : chain\n"); - return(-170); - } + chain = (int *)g_malloc(ncontour * sizeof(int)); /* For each neighboring point in the list (with "i" pointing to the */ /* previous neighbor and "j" pointing to the next neighbor... */ diff --git a/libfprint/nbis/mindtct/contour.c b/libfprint/nbis/mindtct/contour.c index 5d802c2..3e9416c 100644 --- a/libfprint/nbis/mindtct/contour.c +++ b/libfprint/nbis/mindtct/contour.c @@ -110,45 +110,16 @@ int allocate_contour(int **ocontour_x, int **ocontour_y, ASSERT_SIZE_MUL(ncontour, sizeof(int)); /* Allocate contour's x-coord list. */ - contour_x = (int *)malloc(ncontour*sizeof(int)); - /* If allocation error... */ - if(contour_x == (int *)NULL){ - fprintf(stderr, "ERROR : allocate_contour : malloc : contour_x\n"); - return(-180); - } + contour_x = (int *)g_malloc(ncontour * sizeof(int)); /* Allocate contour's y-coord list. */ - contour_y = (int *)malloc(ncontour*sizeof(int)); - /* If allocation error... */ - if(contour_y == (int *)NULL){ - /* Deallocate memory allocated to this point in this routine. */ - free(contour_x); - fprintf(stderr, "ERROR : allocate_contour : malloc : contour_y\n"); - return(-181); - } + contour_y = (int *)g_malloc(ncontour * sizeof(int)); /* Allocate contour's edge x-coord list. */ - contour_ex = (int *)malloc(ncontour*sizeof(int)); - /* If allocation error... */ - if(contour_ex == (int *)NULL){ - /* Deallocate memory allocated to this point in this routine. */ - free(contour_x); - free(contour_y); - fprintf(stderr, "ERROR : allocate_contour : malloc : contour_ex\n"); - return(-182); - } + contour_ex = (int *)g_malloc(ncontour * sizeof(int)); /* Allocate contour's edge y-coord list. */ - contour_ey = (int *)malloc(ncontour*sizeof(int)); - /* If allocation error... */ - if(contour_ey == (int *)NULL){ - /* Deallocate memory allocated to this point in this routine. */ - free(contour_x); - free(contour_y); - free(contour_ex); - fprintf(stderr, "ERROR : allocate_contour : malloc : contour_ey\n"); - return(-183); - } + contour_ey = (int *)g_malloc(ncontour * sizeof(int)); /* Otherwise, allocations successful, so assign output pointers. */ *ocontour_x = contour_x; @@ -181,10 +152,10 @@ int allocate_contour(int **ocontour_x, int **ocontour_y, void free_contour(int *contour_x, int *contour_y, int *contour_ex, int *contour_ey) { - free(contour_x); - free(contour_y); - free(contour_ex); - free(contour_ey); + g_free(contour_x); + g_free(contour_y); + g_free(contour_ex); + g_free(contour_ey); } /************************************************************************* diff --git a/libfprint/nbis/mindtct/detect.c b/libfprint/nbis/mindtct/detect.c index 10ed85c..703579d 100644 --- a/libfprint/nbis/mindtct/detect.c +++ b/libfprint/nbis/mindtct/detect.c @@ -207,15 +207,7 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, } else{ /* If padding is unnecessary, then copy the input image. */ - pdata = (unsigned char *)malloc(iw*ih); - if(pdata == (unsigned char *)NULL){ - /* Free memory allocated to this point. */ - free_dir2rad(dir2rad); - free_dftwaves(dftwaves); - free_rotgrids(dftgrids); - fprintf(stderr, "ERROR : lfs_detect_minutiae_V2 : malloc : pdata\n"); - return(-580); - } + pdata = (unsigned char *)g_malloc(iw * ih); memcpy(pdata, idata, iw*ih); pw = iw; ph = ih; @@ -244,7 +236,7 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, free_dir2rad(dir2rad); free_dftwaves(dftwaves); free_rotgrids(dftgrids); - free(pdata); + g_free(pdata); return(ret); } /* Deallocate working memories. */ @@ -268,11 +260,11 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, lfsparms->dirbin_grid_w, lfsparms->dirbin_grid_h, RELATIVE2CENTER))){ /* Free memory allocated to this point. */ - free(pdata); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); + g_free(pdata); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); + g_free(high_curve_map); return(ret); } @@ -281,11 +273,11 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, pdata, pw, ph, direction_map, mw, mh, dirbingrids, lfsparms))){ /* Free memory allocated to this point. */ - free(pdata); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); + g_free(pdata); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); + g_free(high_curve_map); free_rotgrids(dirbingrids); return(ret); } @@ -297,12 +289,12 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, /* the input image, then ERROR. */ if((iw != bw) || (ih != bh)){ /* Free memory allocated to this point. */ - free(pdata); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); - free(bdata); + g_free(pdata); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); + g_free(high_curve_map); + g_free(bdata); fprintf(stderr, "ERROR : lfs_detect_minutiae_V2 :"); fprintf(stderr,"binary image has bad dimensions : %d, %d\n", bw, bh); @@ -332,12 +324,12 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, direction_map, low_flow_map, high_curve_map, mw, mh, lfsparms))){ /* Free memory allocated to this point. */ - free(pdata); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); - free(bdata); + g_free(pdata); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); + g_free(high_curve_map); + g_free(bdata); return(ret); } @@ -349,12 +341,12 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, direction_map, low_flow_map, high_curve_map, mw, mh, lfsparms))){ /* Free memory allocated to this point. */ - free(pdata); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); - free(bdata); + g_free(pdata); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); + g_free(high_curve_map); + g_free(bdata); free_minutiae(minutiae); return(ret); } @@ -370,11 +362,11 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, if((ret = count_minutiae_ridges(minutiae, bdata, iw, ih, lfsparms))){ /* Free memory allocated to this point. */ - free(pdata); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); + g_free(pdata); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); + g_free(high_curve_map); free_minutiae(minutiae); return(ret); } @@ -393,7 +385,7 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, gray2bin(1, 255, 0, bdata, iw, ih); /* Deallocate working memory. */ - free(pdata); + g_free(pdata); /* Assign results to output pointers. */ *odmap = direction_map; diff --git a/libfprint/nbis/mindtct/dft.c b/libfprint/nbis/mindtct/dft.c index be48586..3b49ecf 100644 --- a/libfprint/nbis/mindtct/dft.c +++ b/libfprint/nbis/mindtct/dft.c @@ -113,11 +113,7 @@ int dft_dir_powers(double **powers, unsigned char *pdata, fprintf(stderr, "ERROR : dft_dir_powers : DFT grids must be square\n"); return(-90); } - rowsums = (int *)malloc(dftgrids->grid_w * sizeof(int)); - if(rowsums == (int *)NULL){ - fprintf(stderr, "ERROR : dft_dir_powers : malloc : rowsums\n"); - return(-91); - } + rowsums = (int *)g_malloc(dftgrids->grid_w * sizeof(int)); memset(rowsums, 0, dftgrids->grid_w * sizeof(int)); /* Foreach direction ... */ @@ -135,7 +131,7 @@ int dft_dir_powers(double **powers, unsigned char *pdata, } /* Deallocate working memory. */ - free(rowsums); + g_free(rowsums); return(0); } @@ -355,11 +351,7 @@ int sort_dft_waves(int *wis, const double *powmaxs, const double *pownorms, double *pownorms2; /* Allocate normalized power^2 array */ - pownorms2 = (double *)malloc(nstats * sizeof(double)); - if(pownorms2 == (double *)NULL){ - fprintf(stderr, "ERROR : sort_dft_waves : malloc : pownorms2\n"); - return(-100); - } + pownorms2 = (double *)g_malloc(nstats * sizeof(double)); for(i = 0; i < nstats; i++){ /* Wis will hold the sorted statistic indices when all is done. */ @@ -372,7 +364,7 @@ int sort_dft_waves(int *wis, const double *powmaxs, const double *pownorms, bubble_sort_double_dec_2(pownorms2, wis, nstats); /* Deallocate the working memory. */ - free(pownorms2); + g_free(pownorms2); return(0); } diff --git a/libfprint/nbis/mindtct/free.c b/libfprint/nbis/mindtct/free.c index adaeeb9..1acd7e2 100644 --- a/libfprint/nbis/mindtct/free.c +++ b/libfprint/nbis/mindtct/free.c @@ -72,9 +72,9 @@ of the software. *************************************************************************/ void free_dir2rad(DIR2RAD *dir2rad) { - free(dir2rad->cos); - free(dir2rad->sin); - free(dir2rad); + g_free(dir2rad->cos); + g_free(dir2rad->sin); + g_free(dir2rad); } /************************************************************************* @@ -90,12 +90,12 @@ void free_dftwaves(DFTWAVES *dftwaves) int i; for(i = 0; i < dftwaves->nwaves; i++){ - free(dftwaves->waves[i]->cos); - free(dftwaves->waves[i]->sin); - free(dftwaves->waves[i]); + g_free(dftwaves->waves[i]->cos); + g_free(dftwaves->waves[i]->sin); + g_free(dftwaves->waves[i]); } - free(dftwaves->waves); - free(dftwaves); + g_free(dftwaves->waves); + g_free(dftwaves); } /************************************************************************* @@ -111,9 +111,9 @@ void free_rotgrids(ROTGRIDS *rotgrids) int i; for(i = 0; i < rotgrids->ngrids; i++) - free(rotgrids->grids[i]); - free(rotgrids->grids); - free(rotgrids); + g_free(rotgrids->grids[i]); + g_free(rotgrids->grids); + g_free(rotgrids); } /************************************************************************* @@ -129,8 +129,8 @@ void free_dir_powers(double **powers, const int nwaves) int w; for(w = 0; w < nwaves; w++) - free(powers[w]); + g_free(powers[w]); - free(powers); + g_free(powers); } diff --git a/libfprint/nbis/mindtct/getmin.c b/libfprint/nbis/mindtct/getmin.c index 08a087d..3597a0a 100644 --- a/libfprint/nbis/mindtct/getmin.c +++ b/libfprint/nbis/mindtct/getmin.c @@ -134,11 +134,11 @@ int get_minutiae(MINUTIAE **ominutiae, int **oquality_map, direction_map, low_contrast_map, low_flow_map, high_curve_map, map_w, map_h))){ free_minutiae(minutiae); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); - free(bdata); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); + g_free(high_curve_map); + g_free(bdata); return(ret); } @@ -147,12 +147,12 @@ int get_minutiae(MINUTIAE **ominutiae, int **oquality_map, lfsparms->blocksize, idata, iw, ih, id, ppmm))){ free_minutiae(minutiae); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); - free(quality_map); - free(bdata); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); + g_free(high_curve_map); + g_free(quality_map); + g_free(bdata); return(ret); } diff --git a/libfprint/nbis/mindtct/imgutil.c b/libfprint/nbis/mindtct/imgutil.c index 50cf766..63f4ec9 100644 --- a/libfprint/nbis/mindtct/imgutil.c +++ b/libfprint/nbis/mindtct/imgutil.c @@ -191,11 +191,7 @@ int pad_uchar_image(unsigned char **optr, int *ow, int *oh, psize = pw * ph; /* Allocate padded image */ - pdata = (unsigned char *)malloc(psize * sizeof(unsigned char)); - if(pdata == (unsigned char *)NULL){ - fprintf(stderr, "ERROR : pad_uchar_image : malloc : pdata\n"); - return(-160); - } + pdata = (unsigned char *)g_malloc(psize * sizeof(unsigned char)); /* Initialize values to a constant PAD value */ memset(pdata, pad_value, psize); @@ -355,8 +351,8 @@ int free_path(const int x1, const int y1, const int x2, const int y2, /* If number of transitions seen > than threshold (ex. 2) ... */ if(trans > lfsparms->maxtrans){ /* Deallocate the line segment's coordinate lists. */ - free(x_list); - free(y_list); + g_free(x_list); + g_free(y_list); /* Return free path to be FALSE. */ return(FALSE); } @@ -370,8 +366,8 @@ int free_path(const int x1, const int y1, const int x2, const int y2, /* If we get here we did not exceed the maximum allowable number */ /* of transitions. So, deallocate the line segment's coordinate lists. */ - free(x_list); - free(y_list); + g_free(x_list); + g_free(y_list); /* Return free path to be TRUE. */ return(TRUE); diff --git a/libfprint/nbis/mindtct/init.c b/libfprint/nbis/mindtct/init.c index 9015228..28e182c 100644 --- a/libfprint/nbis/mindtct/init.c +++ b/libfprint/nbis/mindtct/init.c @@ -91,33 +91,16 @@ int init_dir2rad(DIR2RAD **optr, const int ndirs) double cs, sn; /* Allocate structure */ - dir2rad = (DIR2RAD *)malloc(sizeof(DIR2RAD)); - if(dir2rad == (DIR2RAD *)NULL){ - fprintf(stderr, "ERROR : init_dir2rad : malloc : dir2rad\n"); - return(-10); - } + dir2rad = (DIR2RAD *)g_malloc(sizeof(DIR2RAD)); /* Assign number of directions */ dir2rad->ndirs = ndirs; /* Allocate cosine vector */ - dir2rad->cos = (double *)malloc(ndirs * sizeof(double)); - if(dir2rad->cos == (double *)NULL){ - /* Free memory allocated to this point. */ - free(dir2rad); - fprintf(stderr, "ERROR : init_dir2rad : malloc : dir2rad->cos\n"); - return(-11); - } + dir2rad->cos = (double *)g_malloc(ndirs * sizeof(double)); /* Allocate sine vector */ - dir2rad->sin = (double *)malloc(ndirs * sizeof(double)); - if(dir2rad->sin == (double *)NULL){ - /* Free memory allocated to this point. */ - free(dir2rad->cos); - free(dir2rad); - fprintf(stderr, "ERROR : init_dir2rad : malloc : dir2rad->sin\n"); - return(-12); - } + dir2rad->sin = (double *)g_malloc(ndirs * sizeof(double)); /* Pi_factor sets the period of the trig functions to NDIRS units in x. */ /* For example, if NDIRS==16, then pi_factor = 2(PI/16) = .3926... */ @@ -166,11 +149,7 @@ int init_dftwaves(DFTWAVES **optr, const double *dft_coefs, double *cptr, *sptr; /* Allocate structure */ - dftwaves = (DFTWAVES *)malloc(sizeof(DFTWAVES)); - if(dftwaves == (DFTWAVES *)NULL){ - fprintf(stderr, "ERROR : init_dftwaves : malloc : dftwaves\n"); - return(-20); - } + dftwaves = (DFTWAVES *)g_malloc(sizeof(DFTWAVES)); /* Set number of DFT waves */ dftwaves->nwaves = nwaves; @@ -178,10 +157,10 @@ int init_dftwaves(DFTWAVES **optr, const double *dft_coefs, dftwaves->wavelen = blocksize; /* Allocate list of wave pointers */ - dftwaves->waves = (DFTWAVE **)malloc(nwaves * sizeof(DFTWAVE *)); + dftwaves->waves = (DFTWAVE **)g_malloc(nwaves * sizeof(DFTWAVE *)); if(dftwaves == (DFTWAVES *)NULL){ /* Free memory allocated to this point. */ - free(dftwaves); + g_free(dftwaves); fprintf(stderr, "ERROR : init_dftwaves : malloc : dftwaves->waves\n"); return(-21); } @@ -194,53 +173,11 @@ int init_dftwaves(DFTWAVES **optr, const double *dft_coefs, /* Foreach of 4 DFT frequency coef ... */ for (i = 0; i < nwaves; ++i) { /* Allocate wave structure */ - dftwaves->waves[i] = (DFTWAVE *)malloc(sizeof(DFTWAVE)); - if(dftwaves->waves[i] == (DFTWAVE *)NULL){ - /* Free memory allocated to this point. */ - { int _j; for(_j = 0; _j < i; _j++){ - free(dftwaves->waves[_j]->cos); - free(dftwaves->waves[_j]->sin); - free(dftwaves->waves[_j]); - }} - free(dftwaves->waves); - free(dftwaves); - fprintf(stderr, - "ERROR : init_dftwaves : malloc : dftwaves->waves[i]\n"); - return(-22); - } + dftwaves->waves[i] = (DFTWAVE *)g_malloc(sizeof(DFTWAVE)); /* Allocate cosine vector */ - dftwaves->waves[i]->cos = (double *)malloc(blocksize * sizeof(double)); - if(dftwaves->waves[i]->cos == (double *)NULL){ - /* Free memory allocated to this point. */ - { int _j; for(_j = 0; _j < i; _j++){ - free(dftwaves->waves[_j]->cos); - free(dftwaves->waves[_j]->sin); - free(dftwaves->waves[_j]); - }} - free(dftwaves->waves[i]); - free(dftwaves->waves); - free(dftwaves); - fprintf(stderr, - "ERROR : init_dftwaves : malloc : dftwaves->waves[i]->cos\n"); - return(-23); - } + dftwaves->waves[i]->cos = (double *)g_malloc(blocksize * sizeof(double)); /* Allocate sine vector */ - dftwaves->waves[i]->sin = (double *)malloc(blocksize * sizeof(double)); - if(dftwaves->waves[i]->sin == (double *)NULL){ - /* Free memory allocated to this point. */ - { int _j; for(_j = 0; _j < i; _j++){ - free(dftwaves->waves[_j]->cos); - free(dftwaves->waves[_j]->sin); - free(dftwaves->waves[_j]); - }} - free(dftwaves->waves[i]->cos); - free(dftwaves->waves[i]); - free(dftwaves->waves); - free(dftwaves); - fprintf(stderr, - "ERROR : init_dftwaves : malloc : dftwaves->waves[i]->sin\n"); - return(-24); - } + dftwaves->waves[i]->sin = (double *)g_malloc(blocksize * sizeof(double)); /* Assign pointer nicknames */ cptr = dftwaves->waves[i]->cos; @@ -435,11 +372,7 @@ int init_rotgrids(ROTGRIDS **optr, const int iw, const int ih, const int ipad, double pad; /* Allocate structure */ - rotgrids = (ROTGRIDS *)malloc(sizeof(ROTGRIDS)); - if(rotgrids == (ROTGRIDS *)NULL){ - fprintf(stderr, "ERROR : init_rotgrids : malloc : rotgrids\n"); - return(-30); - } + rotgrids = (ROTGRIDS *)g_malloc(sizeof(ROTGRIDS)); /* Set rotgrid attributes */ rotgrids->ngrids = ndirs; @@ -474,7 +407,7 @@ int init_rotgrids(ROTGRIDS **optr, const int iw, const int ih, const int ipad, fprintf(stderr, "ERROR : init_rotgrids : Illegal relative flag : %d\n", relative2); - free(rotgrids); + g_free(rotgrids); return(-31); } @@ -488,7 +421,7 @@ int init_rotgrids(ROTGRIDS **optr, const int iw, const int ih, const int ipad, if(ipad < grid_pad){ /* If input pad is NOT large enough, then ERROR. */ fprintf(stderr, "ERROR : init_rotgrids : Pad passed is too small\n"); - free(rotgrids); + g_free(rotgrids); return(-32); } /* Otherwise, use the specified input pad in computing grid offsets. */ @@ -506,13 +439,7 @@ int init_rotgrids(ROTGRIDS **optr, const int iw, const int ih, const int ipad, cy = (grid_h-1)/(double)2.0; /* Allocate list of rotgrid pointers */ - rotgrids->grids = (int **)malloc(ndirs * sizeof(int *)); - if(rotgrids->grids == (int **)NULL){ - /* Free memory allocated to this point. */ - free(rotgrids); - fprintf(stderr, "ERROR : init_rotgrids : malloc : rotgrids->grids\n"); - return(-33); - } + rotgrids->grids = (int **)g_malloc(ndirs * sizeof(int *)); /* Pi_offset is the offset in radians from which angles are to begin. */ pi_offset = start_dir_angle; @@ -523,17 +450,7 @@ int init_rotgrids(ROTGRIDS **optr, const int iw, const int ih, const int ipad, dir < ndirs; dir++, theta += pi_incr) { /* Allocate a rotgrid */ - rotgrids->grids[dir] = (int *)malloc(grid_size * sizeof(int)); - if(rotgrids->grids[dir] == (int *)NULL){ - /* Free memory allocated to this point. */ - { int _j; for(_j = 0; _j < dir; _j++){ - free(rotgrids->grids[_j]); - }} - free(rotgrids); - fprintf(stderr, - "ERROR : init_rotgrids : malloc : rotgrids->grids[dir]\n"); - return(-34); - } + rotgrids->grids[dir] = (int *)g_malloc(grid_size * sizeof(int)); /* Set pointer to current grid */ grid = rotgrids->grids[dir]; @@ -635,24 +552,11 @@ int alloc_dir_powers(double ***opowers, const int nwaves, const int ndirs) double **powers; /* Allocate list of double pointers to hold power vectors */ - powers = (double **)malloc(nwaves * sizeof(double*)); - if(powers == (double **)NULL){ - fprintf(stderr, "ERROR : alloc_dir_powers : malloc : powers\n"); - return(-40); - } + powers = (double **)g_malloc(nwaves * sizeof(double *)); /* Foreach DFT wave ... */ for(w = 0; w < nwaves; w++){ /* Allocate power vector for all directions */ - powers[w] = (double *)malloc(ndirs * sizeof(double)); - if(powers[w] == (double *)NULL){ - /* Free memory allocated to this point. */ - { int _j; for(_j = 0; _j < w; _j++){ - free(powers[_j]); - }} - free(powers); - fprintf(stderr, "ERROR : alloc_dir_powers : malloc : powers[w]\n"); - return(-41); - } + powers[w] = (double *)g_malloc(ndirs * sizeof(double)); } *opowers = powers; @@ -697,41 +601,16 @@ int alloc_power_stats(int **owis, double **opowmaxs, int **opowmax_dirs, ASSERT_SIZE_MUL(nstats, sizeof(double)); /* Allocate DFT wave index vector */ - wis = (int *)malloc(nstats * sizeof(int)); - if(wis == (int *)NULL){ - fprintf(stderr, "ERROR : alloc_power_stats : malloc : wis\n"); - return(-50); - } + wis = (int *)g_malloc(nstats * sizeof(int)); /* Allocate max power vector */ - powmaxs = (double *)malloc(nstats * sizeof(double)); - if(powmaxs == (double *)NULL){ - /* Free memory allocated to this point. */ - free(wis); - fprintf(stderr, "ERROR : alloc_power_stats : malloc : powmaxs\n"); - return(-51); - } + powmaxs = (double *)g_malloc(nstats * sizeof(double)); /* Allocate max power direction vector */ - powmax_dirs = (int *)malloc(nstats * sizeof(int)); - if(powmax_dirs == (int *)NULL){ - /* Free memory allocated to this point. */ - free(wis); - free(powmaxs); - fprintf(stderr, "ERROR : alloc_power_stats : malloc : powmax_dirs\n"); - return(-52); - } + powmax_dirs = (int *)g_malloc(nstats * sizeof(int)); /* Allocate normalized power vector */ - pownorms = (double *)malloc(nstats * sizeof(double)); - if(pownorms == (double *)NULL){ - /* Free memory allocated to this point. */ - free(wis); - free(powmaxs); - free(powmax_dirs); - fprintf(stderr, "ERROR : alloc_power_stats : malloc : pownorms\n"); - return(-53); - } + pownorms = (double *)g_malloc(nstats * sizeof(double)); *owis = wis; *opowmaxs = powmaxs; diff --git a/libfprint/nbis/mindtct/line.c b/libfprint/nbis/mindtct/line.c index 07edf18..d556141 100644 --- a/libfprint/nbis/mindtct/line.c +++ b/libfprint/nbis/mindtct/line.c @@ -95,17 +95,8 @@ int line_points(int **ox_list, int **oy_list, int *onum, asize = max(abs(x2-x1)+2, abs(y2-y1)+2); /* Allocate x and y-pixel coordinate lists to length 'asize'. */ - x_list = (int *)malloc(asize*sizeof(int)); - if(x_list == (int *)NULL){ - fprintf(stderr, "ERROR : line_points : malloc : x_list\n"); - return(-410); - } - y_list = (int *)malloc(asize*sizeof(int)); - if(y_list == (int *)NULL){ - free(x_list); - fprintf(stderr, "ERROR : line_points : malloc : y_list\n"); - return(-411); - } + x_list = (int *)g_malloc(asize * sizeof(int)); + y_list = (int *)g_malloc(asize * sizeof(int)); /* Compute delta x and y. */ dx = x2 - x1; @@ -190,8 +181,8 @@ int line_points(int **ox_list, int **oy_list, int *onum, if(i >= asize){ fprintf(stderr, "ERROR : line_points : coord list overflow\n"); - free(x_list); - free(y_list); + g_free(x_list); + g_free(y_list); return(-412); } diff --git a/libfprint/nbis/mindtct/loop.c b/libfprint/nbis/mindtct/loop.c index 2142d18..6ab8ea2 100644 --- a/libfprint/nbis/mindtct/loop.c +++ b/libfprint/nbis/mindtct/loop.c @@ -443,7 +443,7 @@ int is_loop_clockwise(const int *contour_x, const int *contour_y, ret = is_chain_clockwise(chain, nchain, default_ret); /* Free the chain code and return result. */ - free(chain); + g_free(chain); return(ret); } diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index ac3b82d..28e5b5f 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -154,14 +154,14 @@ int gen_image_maps(int **odmap, int **olcmap, int **olfmap, int **ohcmap, &low_flow_map, blkoffs, mw, mh, pdata, pw, ph, dftwaves, dftgrids, lfsparms))){ /* Free memory allocated to this point. */ - free(blkoffs); + g_free(blkoffs); return(ret); } if((ret = morph_TF_map(low_flow_map, mw, mh, lfsparms))){ - free(direction_map); - free(low_contrast_map); - free(low_flow_map); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); return(ret); } @@ -176,9 +176,9 @@ int gen_image_maps(int **odmap, int **olcmap, int **olfmap, int **ohcmap, /* 5. Interpolate INVALID direction blocks with their valid neighbors. */ if((ret = interpolate_direction_map(direction_map, low_contrast_map, mw, mh, lfsparms))){ - free(direction_map); - free(low_contrast_map); - free(low_flow_map); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); return(ret); } @@ -198,14 +198,14 @@ int gen_image_maps(int **odmap, int **olcmap, int **olfmap, int **ohcmap, /* 9. Generate High Curvature Map from interpolated Direction Map. */ if((ret = gen_high_curve_map(&high_curve_map, direction_map, mw, mh, lfsparms))){ - free(direction_map); - free(low_contrast_map); - free(low_flow_map); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); return(ret); } /* Deallocate working memory. */ - free(blkoffs); + g_free(blkoffs); *odmap = direction_map; *olcmap = low_contrast_map; @@ -276,44 +276,26 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, bsize = mw * mh; /* Allocate Direction Map memory */ - direction_map = (int *)malloc(bsize * sizeof(int)); - if(direction_map == (int *)NULL){ - fprintf(stderr, - "ERROR : gen_initial_maps : malloc : direction_map\n"); - return(-550); - } + direction_map = (int *)g_malloc(bsize * sizeof(int)); /* Initialize the Direction Map to INVALID (-1). */ memset(direction_map, INVALID_DIR, bsize * sizeof(int)); /* Allocate Low Contrast Map memory */ - low_contrast_map = (int *)malloc(bsize * sizeof(int)); - if(low_contrast_map == (int *)NULL){ - free(direction_map); - fprintf(stderr, - "ERROR : gen_initial_maps : malloc : low_contrast_map\n"); - return(-551); - } + low_contrast_map = (int *)g_malloc(bsize * sizeof(int)); /* Initialize the Low Contrast Map to FALSE (0). */ memset(low_contrast_map, 0, bsize * sizeof(int)); /* Allocate Low Ridge Flow Map memory */ - low_flow_map = (int *)malloc(bsize * sizeof(int)); - if(low_flow_map == (int *)NULL){ - free(direction_map); - free(low_contrast_map); - fprintf(stderr, - "ERROR : gen_initial_maps : malloc : low_flow_map\n"); - return(-552); - } + low_flow_map = (int *)g_malloc(bsize * sizeof(int)); /* Initialize the Low Flow Map to FALSE (0). */ memset(low_flow_map, 0, bsize * sizeof(int)); /* Allocate DFT directional power vectors */ if((ret = alloc_dir_powers(&powers, dftwaves->nwaves, dftgrids->ngrids))){ /* Free memory allocated to this point. */ - free(direction_map); - free(low_contrast_map); - free(low_flow_map); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); return(ret); } @@ -324,9 +306,9 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, if((ret = alloc_power_stats(&wis, &powmaxs, &powmax_dirs, &pownorms, nstats))){ /* Free memory allocated to this point. */ - free(direction_map); - free(low_contrast_map); - free(low_flow_map); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); free_dir_powers(powers, dftwaves->nwaves); return(ret); } @@ -364,14 +346,14 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, pdata, pw, ph, lfsparms))){ /* If system error ... */ if(ret < 0){ - free(direction_map); - free(low_contrast_map); - free(low_flow_map); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); free_dir_powers(powers, dftwaves->nwaves); - free(wis); - free(powmaxs); - free(powmax_dirs); - free(pownorms); + g_free(wis); + g_free(powmaxs); + g_free(powmax_dirs); + g_free(pownorms); return(ret); } @@ -388,14 +370,14 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, if((ret = dft_dir_powers(powers, pdata, low_contrast_offset, pw, ph, dftwaves, dftgrids))){ /* Free memory allocated to this point. */ - free(direction_map); - free(low_contrast_map); - free(low_flow_map); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); free_dir_powers(powers, dftwaves->nwaves); - free(wis); - free(powmaxs); - free(powmax_dirs); - free(pownorms); + g_free(wis); + g_free(powmaxs); + g_free(powmax_dirs); + g_free(pownorms); return(ret); } @@ -405,14 +387,14 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, if((ret = dft_power_stats(wis, powmaxs, powmax_dirs, pownorms, powers, 1, dftwaves->nwaves, dftgrids->ngrids))){ /* Free memory allocated to this point. */ - free(direction_map); - free(low_contrast_map); - free(low_flow_map); + g_free(direction_map); + g_free(low_contrast_map); + g_free(low_flow_map); free_dir_powers(powers, dftwaves->nwaves); - free(wis); - free(powmaxs); - free(powmax_dirs); - free(pownorms); + g_free(wis); + g_free(powmaxs); + g_free(powmax_dirs); + g_free(pownorms); return(ret); } @@ -452,10 +434,10 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, /* Deallocate working memory */ free_dir_powers(powers, dftwaves->nwaves); - free(wis); - free(powmaxs); - free(powmax_dirs); - free(pownorms); + g_free(wis); + g_free(powmaxs); + g_free(powmax_dirs); + g_free(pownorms); *odmap = direction_map; *olcmap = low_contrast_map; @@ -505,12 +487,7 @@ int interpolate_direction_map(int *direction_map, int *low_contrast_map, /* Allocate output (interpolated) Direction Map. */ ASSERT_SIZE_MUL(mw, mh); ASSERT_SIZE_MUL(mw * mh, sizeof(int)); - omap = (int *)malloc(mw*mh*sizeof(int)); - if(omap == (int *)NULL){ - fprintf(stderr, - "ERROR : interpolate_direction_map : malloc : omap\n"); - return(-520); - } + omap = (int *)g_malloc(mw * mh * sizeof(int)); /* Set pointers to the first block in the maps. */ dptr = direction_map; @@ -650,7 +627,7 @@ int interpolate_direction_map(int *direction_map, int *low_contrast_map, /* Copy the interpolated directions into the input map. */ memcpy(direction_map, omap, mw*mh*sizeof(int)); /* Deallocate the working memory. */ - free(omap); + g_free(omap); /* Return normally. */ return(0); @@ -680,18 +657,9 @@ int morph_TF_map(int *tfmap, const int mw, const int mh, ASSERT_INT_MUL(mw, mh); /* Convert TRUE/FALSE map into a binary byte image. */ - cimage = (unsigned char *)malloc(mw*mh); - if(cimage == (unsigned char *)NULL){ - fprintf(stderr, "ERROR : morph_TF_map : malloc : cimage\n"); - return(-660); - } + cimage = (unsigned char *)g_malloc(mw * mh); - mimage = (unsigned char *)malloc(mw*mh); - if(mimage == (unsigned char *)NULL){ - free(cimage); - fprintf(stderr, "ERROR : morph_TF_map : malloc : mimage\n"); - return(-661); - } + mimage = (unsigned char *)g_malloc(mw * mh); cptr = cimage; mptr = tfmap; @@ -710,8 +678,8 @@ int morph_TF_map(int *tfmap, const int mw, const int mh, *mptr++ = *cptr++; } - free(cimage); - free(mimage); + g_free(cimage); + g_free(mimage); return(0); } @@ -746,20 +714,16 @@ int pixelize_map(int **omap, const int iw, const int ih, ASSERT_SIZE_MUL(iw, ih); ASSERT_SIZE_MUL(iw * ih, sizeof(int)); - pmap = (int *)malloc(iw*ih*sizeof(int)); - if(pmap == (int *)NULL){ - fprintf(stderr, "ERROR : pixelize_map : malloc : pmap\n"); - return(-590); - } + pmap = (int *)g_malloc(iw * ih * sizeof(int)); if((ret = block_offsets(&blkoffs, &bw, &bh, iw, ih, 0, blocksize))){ - free(pmap); + g_free(pmap); return(ret); } if((bw != mw) || (bh != mh)){ - free(blkoffs); - free(pmap); + g_free(blkoffs); + g_free(pmap); fprintf(stderr, "ERROR : pixelize_map : block dimensions do not match\n"); return(-591); @@ -777,7 +741,7 @@ int pixelize_map(int **omap, const int iw, const int ih, } /* Deallocate working memory. */ - free(blkoffs); + g_free(blkoffs); /* Assign pixelized map to output pointer. */ *omap = pmap; @@ -910,12 +874,7 @@ int gen_high_curve_map(int **ohcmap, int *direction_map, /* Allocate High Curvature Map. */ ASSERT_SIZE_MUL(mapsize, sizeof(int)); - high_curve_map = (int *)malloc(mapsize * sizeof(int)); - if(high_curve_map == (int *)NULL){ - fprintf(stderr, - "ERROR: gen_high_curve_map : malloc : high_curve_map\n"); - return(-530); - } + high_curve_map = (int *)g_malloc(mapsize * sizeof(int)); /* Initialize High Curvature Map to FALSE (0). */ memset(high_curve_map, 0, mapsize*sizeof(int)); diff --git a/libfprint/nbis/mindtct/minutia.c b/libfprint/nbis/mindtct/minutia.c index ca0d551..0b29aa0 100644 --- a/libfprint/nbis/mindtct/minutia.c +++ b/libfprint/nbis/mindtct/minutia.c @@ -118,16 +118,8 @@ int alloc_minutiae(MINUTIAE **ominutiae, const int DEFAULT_BOZORTH_MINUTIAE) { MINUTIAE *minutiae; - minutiae = (MINUTIAE *)malloc(sizeof(MINUTIAE)); - if(minutiae == (MINUTIAE *)NULL){ - fprintf(stderr, "ERROR : alloc_minutiae : malloc : minutiae\n"); - exit(-430); - } - minutiae->list = (MINUTIA **)malloc(DEFAULT_BOZORTH_MINUTIAE * sizeof(MINUTIA *)); - if(minutiae->list == (MINUTIA **)NULL){ - fprintf(stderr, "ERROR : alloc_minutiae : malloc : minutiae->list\n"); - exit(-431); - } + minutiae = (MINUTIAE *)g_malloc(sizeof(MINUTIAE)); + minutiae->list = (MINUTIA **)g_malloc(DEFAULT_BOZORTH_MINUTIAE * sizeof(MINUTIA *)); minutiae->alloc = DEFAULT_BOZORTH_MINUTIAE; minutiae->num = 0; @@ -154,12 +146,8 @@ int alloc_minutiae(MINUTIAE **ominutiae, const int DEFAULT_BOZORTH_MINUTIAE) int realloc_minutiae(MINUTIAE *minutiae, const int incr_minutiae) { minutiae->alloc += incr_minutiae; - minutiae->list = (MINUTIA **)realloc(minutiae->list, - minutiae->alloc * sizeof(MINUTIA *)); - if(minutiae->list == (MINUTIA **)NULL){ - fprintf(stderr, "ERROR : realloc_minutiae : realloc : minutiae->list\n"); - exit(-432); - } + minutiae->list = (MINUTIA **)g_realloc(minutiae->list, + minutiae->alloc * sizeof(MINUTIA *)); return(0); } @@ -227,37 +215,37 @@ int detect_minutiae_V2(MINUTIAE *minutiae, if((ret = pixelize_map(&plow_flow_map, iw, ih, low_flow_map, mw, mh, lfsparms->blocksize))){ - free(pdirection_map); + g_free(pdirection_map); return(ret); } if((ret = pixelize_map(&phigh_curve_map, iw, ih, high_curve_map, mw, mh, lfsparms->blocksize))){ - free(pdirection_map); - free(plow_flow_map); + g_free(pdirection_map); + g_free(plow_flow_map); return(ret); } if((ret = scan4minutiae_horizontally_V2(minutiae, bdata, iw, ih, pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){ - free(pdirection_map); - free(plow_flow_map); - free(phigh_curve_map); + g_free(pdirection_map); + g_free(plow_flow_map); + g_free(phigh_curve_map); return(ret); } if((ret = scan4minutiae_vertically_V2(minutiae, bdata, iw, ih, pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){ - free(pdirection_map); - free(plow_flow_map); - free(phigh_curve_map); + g_free(pdirection_map); + g_free(plow_flow_map); + g_free(phigh_curve_map); return(ret); } /* Deallocate working memories. */ - free(pdirection_map); - free(plow_flow_map); - free(phigh_curve_map); + g_free(pdirection_map); + g_free(plow_flow_map); + g_free(phigh_curve_map); /* Return normally. */ return(0); @@ -550,11 +538,7 @@ int sort_minutiae_y_x(MINUTIAE *minutiae, const int iw, const int ih) /* Allocate a list of integers to hold 1-D image pixel offsets */ /* for each of the 2-D minutia coordinate points. */ - ranks = (int *)malloc(minutiae->num * sizeof(int)); - if(ranks == (int *)NULL){ - fprintf(stderr, "ERROR : sort_minutiae_y_x : malloc : ranks\n"); - return(-310); - } + ranks = (int *)g_malloc(minutiae->num * sizeof(int)); /* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */ for(i = 0; i < minutiae->num; i++) @@ -562,31 +546,25 @@ int sort_minutiae_y_x(MINUTIAE *minutiae, const int iw, const int ih) /* Get sorted order of minutiae. */ if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){ - free(ranks); + g_free(ranks); return(ret); } /* Allocate new MINUTIA list to hold sorted minutiae. */ - newlist = (MINUTIA **)malloc(minutiae->num * sizeof(MINUTIA *)); - if(newlist == (MINUTIA **)NULL){ - free(ranks); - free(order); - fprintf(stderr, "ERROR : sort_minutiae_y_x : malloc : newlist\n"); - return(-311); - } + newlist = (MINUTIA **)g_malloc(minutiae->num * sizeof(MINUTIA *)); /* Put minutia into sorted order in new list. */ for(i = 0; i < minutiae->num; i++) newlist[i] = minutiae->list[order[i]]; /* Deallocate non-sorted list of minutia pointers. */ - free(minutiae->list); + g_free(minutiae->list); /* Assign new sorted list of minutia to minutiae list. */ minutiae->list = newlist; /* Free the working memories supporting the sort. */ - free(order); - free(ranks); + g_free(order); + g_free(ranks); /* Return normally. */ return(0); @@ -615,11 +593,7 @@ int sort_minutiae_x_y(MINUTIAE *minutiae, const int iw, const int ih) /* Allocate a list of integers to hold 1-D image pixel offsets */ /* for each of the 2-D minutia coordinate points. */ - ranks = (int *)malloc(minutiae->num * sizeof(int)); - if(ranks == (int *)NULL){ - fprintf(stderr, "ERROR : sort_minutiae_x_y : malloc : ranks\n"); - return(-440); - } + ranks = (int *)g_malloc(minutiae->num * sizeof(int)); /* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */ for(i = 0; i < minutiae->num; i++) @@ -627,31 +601,25 @@ int sort_minutiae_x_y(MINUTIAE *minutiae, const int iw, const int ih) /* Get sorted order of minutiae. */ if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){ - free(ranks); + g_free(ranks); return(ret); } /* Allocate new MINUTIA list to hold sorted minutiae. */ - newlist = (MINUTIA **)malloc(minutiae->num * sizeof(MINUTIA *)); - if(newlist == (MINUTIA **)NULL){ - free(ranks); - free(order); - fprintf(stderr, "ERROR : sort_minutiae_x_y : malloc : newlist\n"); - return(-441); - } + newlist = (MINUTIA **)g_malloc(minutiae->num * sizeof(MINUTIA *)); /* Put minutia into sorted order in new list. */ for(i = 0; i < minutiae->num; i++) newlist[i] = minutiae->list[order[i]]; /* Deallocate non-sorted list of minutia pointers. */ - free(minutiae->list); + g_free(minutiae->list); /* Assign new sorted list of minutia to minutiae list. */ minutiae->list = newlist; /* Free the working memories supporting the sort. */ - free(order); - free(ranks); + g_free(order); + g_free(ranks); /* Return normally. */ return(0); @@ -764,12 +732,7 @@ int create_minutia(MINUTIA **ominutia, const int x_loc, const int y_loc, MINUTIA *minutia; /* Allocate a minutia structure. */ - minutia = (MINUTIA *)malloc(sizeof(MINUTIA)); - /* If allocation error... */ - if(minutia == (MINUTIA *)NULL){ - fprintf(stderr, "ERROR : create_minutia : malloc : minutia\n"); - return(-230); - } + minutia = (MINUTIA *)g_malloc(sizeof(MINUTIA)); /* Assign minutia structure attributes. */ minutia->x = x_loc; @@ -807,10 +770,10 @@ void free_minutiae(MINUTIAE *minutiae) for(i = 0; i < minutiae->num; i++) free_minutia(minutiae->list[i]); /* Deallocate list of minutia pointers. */ - free(minutiae->list); + g_free(minutiae->list); /* Deallocate the list structure. */ - free(minutiae); + g_free(minutiae); } /************************************************************************* @@ -825,12 +788,12 @@ void free_minutia(MINUTIA *minutia) { /* Deallocate sublists. */ if(minutia->nbrs != (int *)NULL) - free(minutia->nbrs); + g_free(minutia->nbrs); if(minutia->ridge_counts != (int *)NULL) - free(minutia->ridge_counts); + g_free(minutia->ridge_counts); /* Deallocate the minutia structure. */ - free(minutia); + g_free(minutia); } /************************************************************************* diff --git a/libfprint/nbis/mindtct/quality.c b/libfprint/nbis/mindtct/quality.c index 94e9b63..399c477 100644 --- a/libfprint/nbis/mindtct/quality.c +++ b/libfprint/nbis/mindtct/quality.c @@ -118,11 +118,7 @@ int gen_quality_map(int **oqmap, int *direction_map, int *low_contrast_map, ASSERT_SIZE_MUL(map_w, map_h); ASSERT_SIZE_MUL(map_w * map_h, sizeof(int)); - QualMap = (int *)malloc(map_w * map_h * sizeof(int)); - if(QualMap == (int *)NULL){ - fprintf(stderr, "ERROR : gen_quality_map : malloc : QualMap\n"); - return(-2); - } + QualMap = (int *)g_malloc(map_w * map_h * sizeof(int)); /* Foreach row of blocks in maps ... */ for(thisY=0; thisYreliability = reliability; } /* NEW 05-08-2002 */ - free(pquality_map); + g_free(pquality_map); /* Return normally. */ return(0); diff --git a/libfprint/nbis/mindtct/remove.c b/libfprint/nbis/mindtct/remove.c index faa6607..af5ab7d 100644 --- a/libfprint/nbis/mindtct/remove.c +++ b/libfprint/nbis/mindtct/remove.c @@ -380,7 +380,7 @@ int remove_hooks(MINUTIAE *minutiae, if((deltadir = closest_dir_dist(minutia1->direction, minutia2->direction, full_ndirs)) == INVALID_DIR){ - free(to_remove); + g_free(to_remove); fprintf(stderr, "ERROR : remove_hooks : INVALID direction\n"); return(-641); @@ -424,7 +424,7 @@ int remove_hooks(MINUTIAE *minutiae, } /* If system error occurred during hook test ... */ else if (ret < 0){ - free(to_remove); + g_free(to_remove); return(ret); } /* Otherwise, no hook found, so skip to next */ @@ -474,14 +474,14 @@ int remove_hooks(MINUTIAE *minutiae, if(to_remove[i]){ /* Remove the minutia from the minutiae list. */ if((ret = remove_minutia(i, minutiae))){ - free(to_remove); + g_free(to_remove); return(ret); } } } /* Deallocate flag list. */ - free(to_remove); + g_free(to_remove); /* Return normally. */ return(0); @@ -641,7 +641,7 @@ int remove_islands_and_lakes(MINUTIAE *minutiae, if((deltadir = closest_dir_dist(minutia1->direction, minutia2->direction, full_ndirs)) == INVALID_DIR){ - free(to_remove); + g_free(to_remove); fprintf(stderr, "ERROR : remove_islands_and_lakes : INVALID direction\n"); return(-611); @@ -673,7 +673,7 @@ int remove_islands_and_lakes(MINUTIAE *minutiae, bdata, iw, ih))){ free_contour(loop_x, loop_y, loop_ex, loop_ey); - free(to_remove); + g_free(to_remove); return(ret); } /* Set to remove first minutia. */ @@ -696,7 +696,7 @@ int remove_islands_and_lakes(MINUTIAE *minutiae, } /* If ERROR while looking for island/lake ... */ else if (ret < 0){ - free(to_remove); + g_free(to_remove); return(ret); } else @@ -741,14 +741,14 @@ int remove_islands_and_lakes(MINUTIAE *minutiae, if(to_remove[i]){ /* Remove the minutia from the minutiae list. */ if((ret = remove_minutia(i, minutiae))){ - free(to_remove); + g_free(to_remove); return(ret); } } } /* Deallocate flag list. */ - free(to_remove); + g_free(to_remove); /* Return normally. */ return(0); @@ -950,8 +950,8 @@ int remove_malformations(MINUTIAE *minutiae, print2log("%d,%d RMMAL3 (%f)\n", minutia->x, minutia->y, ratio); if((ret = remove_minutia(i, minutiae))){ - free(x_list); - free(y_list); + g_free(x_list); + g_free(y_list); /* If system error, return error code. */ return(ret); } @@ -961,8 +961,8 @@ int remove_malformations(MINUTIAE *minutiae, } } - free(x_list); - free(y_list); + g_free(x_list); + g_free(y_list); } } @@ -1447,7 +1447,7 @@ int remove_overlaps(MINUTIAE *minutiae, if((deltadir = closest_dir_dist(minutia1->direction, minutia2->direction, full_ndirs)) == INVALID_DIR){ - free(to_remove); + g_free(to_remove); fprintf(stderr, "ERROR : remove_overlaps : INVALID direction\n"); return(-651); @@ -1546,14 +1546,14 @@ int remove_overlaps(MINUTIAE *minutiae, if(to_remove[i]){ /* Remove the minutia from the minutiae list. */ if((ret = remove_minutia(i, minutiae))){ - free(to_remove); + g_free(to_remove); return(ret); } } } /* Deallocate flag list. */ - free(to_remove); + g_free(to_remove); /* Return normally. */ return(0); @@ -2034,12 +2034,7 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, /* Allocate working memory for holding rotated y-coord of a */ /* minutia's contour. */ - rot_y = (int *)malloc(((lfsparms->side_half_contour<<1)+1) * sizeof(int)); - if(rot_y == (int *)NULL){ - fprintf(stderr, - "ERROR : remove_or_adjust_side_minutiae_V2 : malloc : rot_y\n"); - return(-630); - } + rot_y = (int *)g_malloc(((lfsparms->side_half_contour << 1) + 1) * sizeof(int)); /* Compute factor for converting integer directions to radians. */ pi_factor = M_PI / (double)lfsparms->num_directions; @@ -2061,7 +2056,7 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, /* If system error occurred ... */ if(ret < 0){ /* Deallocate working memory. */ - free(rot_y); + g_free(rot_y); /* Return error code. */ return(ret); } @@ -2077,7 +2072,7 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, /* Remove minutia from list. */ if((ret = remove_minutia(i, minutiae))){ /* Deallocate working memory. */ - free(rot_y); + g_free(rot_y); /* Return error code. */ return(ret); } @@ -2130,7 +2125,7 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, &minmax_alloc, &minmax_num, rot_y, ncontour))){ /* If system error, then deallocate working memories. */ - free(rot_y); + g_free(rot_y); free_contour(contour_x, contour_y, contour_ex, contour_ey); /* Return error code. */ return(ret); @@ -2156,12 +2151,12 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, /* Remove minutia from list. */ if((ret = remove_minutia(i, minutiae))){ /* Deallocate working memory. */ - free(rot_y); + g_free(rot_y); free_contour(contour_x, contour_y, contour_ex, contour_ey); if(minmax_alloc > 0){ - free(minmax_val); - free(minmax_type); - free(minmax_i); + g_free(minmax_val); + g_free(minmax_type); + g_free(minmax_i); } /* Return error code. */ return(ret); @@ -2202,12 +2197,12 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, /* Remove minutia from list. */ if((ret = remove_minutia(i, minutiae))){ /* Deallocate working memory. */ - free(rot_y); + g_free(rot_y); free_contour(contour_x, contour_y, contour_ex, contour_ey); if(minmax_alloc > 0){ - free(minmax_val); - free(minmax_type); - free(minmax_i); + g_free(minmax_val); + g_free(minmax_type); + g_free(minmax_i); } /* Return error code. */ return(ret); @@ -2231,12 +2226,12 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, /* Remove minutia from list. */ if((ret = remove_minutia(i, minutiae))){ /* If system error, then deallocate working memories. */ - free(rot_y); + g_free(rot_y); free_contour(contour_x, contour_y, contour_ex, contour_ey); if(minmax_alloc > 0){ - free(minmax_val); - free(minmax_type); - free(minmax_i); + g_free(minmax_val); + g_free(minmax_type); + g_free(minmax_i); } /* Return error code. */ return(ret); @@ -2248,15 +2243,15 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, /* Deallocate contour and min/max buffers. */ free_contour(contour_x, contour_y, contour_ex, contour_ey); if(minmax_alloc > 0){ - free(minmax_val); - free(minmax_type); - free(minmax_i); + g_free(minmax_val); + g_free(minmax_type); + g_free(minmax_i); } } /* End else contour extracted. */ } /* End while not end of minutiae list. */ /* Deallocate working memory. */ - free(rot_y); + g_free(rot_y); /* Return normally. */ return(0); diff --git a/libfprint/nbis/mindtct/ridges.c b/libfprint/nbis/mindtct/ridges.c index 8f69fb2..f0d9cd3 100644 --- a/libfprint/nbis/mindtct/ridges.c +++ b/libfprint/nbis/mindtct/ridges.c @@ -152,7 +152,7 @@ int count_minutia_ridges(const int first, MINUTIAE *minutiae, if((ret = find_neighbors(&nbr_list, &nnbrs, lfsparms->max_nbrs, first, minutiae))){ if (nbr_list != NULL) - free(nbr_list); + g_free(nbr_list); return(ret); } @@ -167,18 +167,13 @@ int count_minutia_ridges(const int first, MINUTIAE *minutiae, /* Sort neighbors on delta dirs. */ if((ret = sort_neighbors(nbr_list, nnbrs, first, minutiae))){ - free(nbr_list); + g_free(nbr_list); return(ret); } /* Count ridges between first and neighbors. */ /* List of ridge counts, one for each neighbor stored. */ - nbr_nridges = (int *)malloc(nnbrs * sizeof(int)); - if(nbr_nridges == (int *)NULL){ - free(nbr_list); - fprintf(stderr, "ERROR : count_minutia_ridges : malloc : nbr_nridges\n"); - return(-450); - } + nbr_nridges = (int *)g_malloc(nnbrs * sizeof(int)); /* Foreach neighbor found and sorted in list ... */ for(i = 0; i < nnbrs; i++){ @@ -187,8 +182,8 @@ int count_minutia_ridges(const int first, MINUTIAE *minutiae, /* If system error ... */ if(ret < 0){ /* Deallocate working memories. */ - free(nbr_list); - free(nbr_nridges); + g_free(nbr_list); + g_free(nbr_nridges); /* Return error code. */ return(ret); } @@ -235,21 +230,11 @@ int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, double *nbr_sqr_dists, xdist, xdist2; /* Allocate list of neighbor minutiae indices. */ - nbr_list = (int *)malloc(max_nbrs * sizeof(int)); - if(nbr_list == (int *)NULL){ - fprintf(stderr, "ERROR : find_neighbors : malloc : nbr_list\n"); - return(-460); - } + nbr_list = (int *)g_malloc(max_nbrs * sizeof(int)); /* Allocate list of squared euclidean distances between neighbors */ /* and current primary minutia point. */ - nbr_sqr_dists = (double *)malloc(max_nbrs * sizeof(double)); - if(nbr_sqr_dists == (double *)NULL){ - free(nbr_list); - fprintf(stderr, - "ERROR : find_neighbors : malloc : nbr_sqr_dists\n"); - return(-461); - } + nbr_sqr_dists = (double *)g_malloc(max_nbrs * sizeof(double)); /* Initialize number of stored neighbors to 0. */ nnbrs = 0; @@ -280,8 +265,8 @@ int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, /* Append or insert the new neighbor into the neighbor lists. */ if((ret = update_nbr_dists(nbr_list, nbr_sqr_dists, &nnbrs, max_nbrs, first, second, minutiae))){ - free(nbr_sqr_dists); - free(nbr_list); + g_free(nbr_sqr_dists); + g_free(nbr_list); return(ret); } } @@ -297,12 +282,12 @@ int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, } /* Deallocate working memory. */ - free(nbr_sqr_dists); + g_free(nbr_sqr_dists); /* If no neighbors found ... */ if(nnbrs == 0){ /* Deallocate the neighbor list. */ - free(nbr_list); + g_free(nbr_list); *onnbrs = 0; } /* Otherwise, assign neighbors to output pointer. */ @@ -497,11 +482,7 @@ int sort_neighbors(int *nbr_list, const int nnbrs, const int first, /* List of angles of lines joining the current primary to each */ /* of the secondary neighbors. */ - join_thetas = (double *)malloc(nnbrs * sizeof(double)); - if(join_thetas == (double *)NULL){ - fprintf(stderr, "ERROR : sort_neighbors : malloc : join_thetas\n"); - return(-490); - } + join_thetas = (double *)g_malloc(nnbrs * sizeof(double)); for(i = 0; i < nnbrs; i++){ /* Compute angle to line connecting the 2 points. */ @@ -523,7 +504,7 @@ int sort_neighbors(int *nbr_list, const int nnbrs, const int first, bubble_sort_double_inc_2(join_thetas, nbr_list, nnbrs); /* Deallocate the list of angles. */ - free(join_thetas); + g_free(join_thetas); /* Return normally. */ return(0); @@ -576,8 +557,8 @@ int ridge_count(const int first, const int second, MINUTIAE *minutiae, /* It there are no points on the line trajectory, then no ridges */ /* to count (this should not happen, but just in case) ... */ if(num == 0){ - free(xlist); - free(ylist); + g_free(xlist); + g_free(ylist); return(0); } @@ -597,8 +578,8 @@ int ridge_count(const int first, const int second, MINUTIAE *minutiae, /* If opposite pixel not found ... then no ridges to count */ if(!found){ - free(xlist); - free(ylist); + g_free(xlist); + g_free(ylist); return(0); } @@ -613,8 +594,8 @@ int ridge_count(const int first, const int second, MINUTIAE *minutiae, /* If 0-to-1 transition not found ... */ if(!find_transition(&i, 0, 1, xlist, ylist, num, bdata, iw, ih)){ /* Then we are done looking for ridges. */ - free(xlist); - free(ylist); + g_free(xlist); + g_free(ylist); print2log("\n"); @@ -630,8 +611,8 @@ int ridge_count(const int first, const int second, MINUTIAE *minutiae, /* If 1-to-0 transition not found ... */ if(!find_transition(&i, 1, 0, xlist, ylist, num, bdata, iw, ih)){ /* Then we are done looking for ridges. */ - free(xlist); - free(ylist); + g_free(xlist); + g_free(ylist); print2log("\n"); @@ -657,8 +638,8 @@ int ridge_count(const int first, const int second, MINUTIAE *minutiae, /* If system error ... */ if(ret < 0){ - free(xlist); - free(ylist); + g_free(xlist); + g_free(ylist); /* Return the error code. */ return(ret); } @@ -677,8 +658,8 @@ int ridge_count(const int first, const int second, MINUTIAE *minutiae, } /* Deallocate working memories. */ - free(xlist); - free(ylist); + g_free(xlist); + g_free(ylist); print2log("\n"); diff --git a/libfprint/nbis/mindtct/shape.c b/libfprint/nbis/mindtct/shape.c index 5f9e7bc..28bc66c 100644 --- a/libfprint/nbis/mindtct/shape.c +++ b/libfprint/nbis/mindtct/shape.c @@ -98,23 +98,11 @@ int alloc_shape(SHAPE **oshape, const int xmin, const int ymin, alloc_pts = xmax - xmin + 1; /* Allocate the shape structure. */ - shape = (SHAPE *)malloc(sizeof(SHAPE)); - /* If there is an allocation error... */ - if(shape == (SHAPE *)NULL){ - fprintf(stderr, "ERROR : alloc_shape : malloc : shape\n"); - return(-250); - } + shape = (SHAPE *)g_malloc(sizeof(SHAPE)); /* Allocate the list of row pointers. We now this number will fit */ /* the shape exactly. */ - shape->rows = (ROW **)malloc(alloc_rows * sizeof(ROW *)); - /* If there is an allocation error... */ - if(shape->rows == (ROW **)NULL){ - /* Deallocate memory alloated by this routine to this point. */ - free(shape); - fprintf(stderr, "ERROR : alloc_shape : malloc : shape->rows\n"); - return(-251); - } + shape->rows = (ROW **)g_malloc(alloc_rows * sizeof(ROW *)); /* Initialize the shape structure's attributes. */ shape->ymin = ymin; @@ -128,36 +116,10 @@ int alloc_shape(SHAPE **oshape, const int xmin, const int ymin, for(i = 0, y = ymin; i < alloc_rows; i++, y++){ /* Allocate a row structure and store it in its respective position */ /* in the shape structure's list of row pointers. */ - shape->rows[i] = (ROW *)malloc(sizeof(ROW)); - /* If there is an allocation error... */ - if(shape->rows[i] == (ROW *)NULL){ - /* Deallocate memory alloated by this routine to this point. */ - for(j = 0; j < i; j++){ - free(shape->rows[j]->xs); - free(shape->rows[j]); - } - free(shape->rows); - free(shape); - fprintf(stderr, "ERROR : alloc_shape : malloc : shape->rows[i]\n"); - return(-252); - } + shape->rows[i] = (ROW *)g_malloc(sizeof(ROW)); /* Allocate the current rows list of x-coords. */ - shape->rows[i]->xs = (int *)malloc(alloc_pts * sizeof(int)); - /* If there is an allocation error... */ - if(shape->rows[i]->xs == (int *)NULL){ - /* Deallocate memory alloated by this routine to this point. */ - for(j = 0; j < i; j++){ - free(shape->rows[j]->xs); - free(shape->rows[j]); - } - free(shape->rows[i]); - free(shape->rows); - free(shape); - fprintf(stderr, - "ERROR : alloc_shape : malloc : shape->rows[i]->xs\n"); - return(-253); - } + shape->rows[i]->xs = (int *)g_malloc(alloc_pts * sizeof(int)); /* Initialize the current row structure's attributes. */ shape->rows[i]->y = y; @@ -188,15 +150,15 @@ void free_shape(SHAPE *shape) /* Foreach allocated row in the shape ... */ for(i = 0; i < shape->alloc; i++){ /* Deallocate the current row's list of x-coords. */ - free(shape->rows[i]->xs); + g_free(shape->rows[i]->xs); /* Deallocate the current row structure. */ - free(shape->rows[i]); + g_free(shape->rows[i]); } /* Deallocate the list of row pointers. */ - free(shape->rows); + g_free(shape->rows); /* Deallocate the shape structure. */ - free(shape); + g_free(shape); } /************************************************************************* @@ -260,7 +222,7 @@ int shape_from_contour(SHAPE **oshape, const int *contour_x, if(row->npts >= row->alloc){ /* This should never happen becuase we have allocated */ /* based on shape bounding limits. */ - free(shape); + g_free(shape); fprintf(stderr, "ERROR : shape_from_contour : row overflow\n"); return(-260); diff --git a/libfprint/nbis/mindtct/sort.c b/libfprint/nbis/mindtct/sort.c index 9080ce0..5343639 100644 --- a/libfprint/nbis/mindtct/sort.c +++ b/libfprint/nbis/mindtct/sort.c @@ -89,11 +89,7 @@ int sort_indices_int_inc(int **optr, int *ranks, const int num) int i; /* Allocate list of sequential indices. */ - order = (int *)malloc(num * sizeof(int)); - if(order == (int *)NULL){ - fprintf(stderr, "ERROR : sort_indices_int_inc : malloc : order\n"); - return(-390); - } + order = (int *)g_malloc(num * sizeof(int)); /* Initialize list of sequential indices. */ for(i = 0; i < num; i++) order[i] = i; diff --git a/libfprint/nbis/mindtct/util.c b/libfprint/nbis/mindtct/util.c index 1662e62..5ae1199 100644 --- a/libfprint/nbis/mindtct/util.c +++ b/libfprint/nbis/mindtct/util.c @@ -178,24 +178,9 @@ int minmaxs(int **ominmax_val, int **ominmax_type, int **ominmax_i, /* min or max. */ minmax_alloc = num - 2; /* Allocate the buffers. */ - minmax_val = (int *)malloc(minmax_alloc * sizeof(int)); - if(minmax_val == (int *)NULL){ - fprintf(stderr, "ERROR : minmaxs : malloc : minmax_val\n"); - return(-290); - } - minmax_type = (int *)malloc(minmax_alloc * sizeof(int)); - if(minmax_type == (int *)NULL){ - free(minmax_val); - fprintf(stderr, "ERROR : minmaxs : malloc : minmax_type\n"); - return(-291); - } - minmax_i = (int *)malloc(minmax_alloc * sizeof(int)); - if(minmax_i == (int *)NULL){ - free(minmax_val); - free(minmax_type); - fprintf(stderr, "ERROR : minmaxs : malloc : minmax_i\n"); - return(-292); - } + minmax_val = (int *)g_malloc(minmax_alloc * sizeof(int)); + minmax_type = (int *)g_malloc(minmax_alloc * sizeof(int)); + minmax_i = (int *)g_malloc(minmax_alloc * sizeof(int)); /* Initialize number of min/max to 0. */ minmax_num = 0;