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.
This commit is contained in:
Benjamin Berg 2019-06-27 19:21:17 +02:00 committed by Marco Trevisan (Treviño)
parent 56543e1311
commit 30a449841c
20 changed files with 273 additions and 628 deletions

View file

@ -214,11 +214,7 @@ int binarize_image_V2(unsigned char **odata, int *ow, int *oh,
bw = pw - (dirbingrids->pad<<1); bw = pw - (dirbingrids->pad<<1);
bh = ph - (dirbingrids->pad<<1); bh = ph - (dirbingrids->pad<<1);
bdata = (unsigned char *)malloc(bw*bh*sizeof(unsigned char)); bdata = (unsigned char *)g_malloc(bw * bh * sizeof(unsigned char));
if(bdata == (unsigned char *)NULL){
fprintf(stderr, "ERROR : binarize_image_V2 : malloc : bdata\n");
return(-600);
}
bptr = bdata; bptr = bdata;
spptr = pdata + (dirbingrids->pad * pw) + dirbingrids->pad; spptr = pdata + (dirbingrids->pad * pw) + dirbingrids->pad;

View file

@ -134,11 +134,7 @@ int block_offsets(int **optr, int *ow, int *oh,
lastbh = bh - 1; lastbh = bh - 1;
/* Allocate list of block offsets */ /* Allocate list of block offsets */
blkoffs = (int *)malloc(bsize * sizeof(int)); blkoffs = (int *)g_malloc(bsize * sizeof(int));
if(blkoffs == (int *)NULL){
fprintf(stderr, "ERROR : block_offsets : malloc : blkoffs\n");
return(-81);
}
/* Current block index */ /* Current block index */
bi = 0; bi = 0;

View file

@ -100,12 +100,7 @@ int chain_code_loop(int **ochain, int *onchain,
/* number of points in the contour. There will be one chain code */ /* number of points in the contour. There will be one chain code */
/* between each point on the contour including a code between the */ /* between each point on the contour including a code between the */
/* last to the first point on the contour (completing the loop). */ /* last to the first point on the contour (completing the loop). */
chain = (int *)malloc(ncontour * sizeof(int)); chain = (int *)g_malloc(ncontour * sizeof(int));
/* If the allocation fails ... */
if(chain == (int *)NULL){
fprintf(stderr, "ERROR : chain_code_loop : malloc : chain\n");
return(-170);
}
/* For each neighboring point in the list (with "i" pointing to the */ /* For each neighboring point in the list (with "i" pointing to the */
/* previous neighbor and "j" pointing to the next neighbor... */ /* previous neighbor and "j" pointing to the next neighbor... */

View file

@ -110,45 +110,16 @@ int allocate_contour(int **ocontour_x, int **ocontour_y,
ASSERT_SIZE_MUL(ncontour, sizeof(int)); ASSERT_SIZE_MUL(ncontour, sizeof(int));
/* Allocate contour's x-coord list. */ /* Allocate contour's x-coord list. */
contour_x = (int *)malloc(ncontour*sizeof(int)); contour_x = (int *)g_malloc(ncontour * sizeof(int));
/* If allocation error... */
if(contour_x == (int *)NULL){
fprintf(stderr, "ERROR : allocate_contour : malloc : contour_x\n");
return(-180);
}
/* Allocate contour's y-coord list. */ /* Allocate contour's y-coord list. */
contour_y = (int *)malloc(ncontour*sizeof(int)); contour_y = (int *)g_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);
}
/* Allocate contour's edge x-coord list. */ /* Allocate contour's edge x-coord list. */
contour_ex = (int *)malloc(ncontour*sizeof(int)); contour_ex = (int *)g_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);
}
/* Allocate contour's edge y-coord list. */ /* Allocate contour's edge y-coord list. */
contour_ey = (int *)malloc(ncontour*sizeof(int)); contour_ey = (int *)g_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);
}
/* Otherwise, allocations successful, so assign output pointers. */ /* Otherwise, allocations successful, so assign output pointers. */
*ocontour_x = contour_x; *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, void free_contour(int *contour_x, int *contour_y,
int *contour_ex, int *contour_ey) int *contour_ex, int *contour_ey)
{ {
free(contour_x); g_free(contour_x);
free(contour_y); g_free(contour_y);
free(contour_ex); g_free(contour_ex);
free(contour_ey); g_free(contour_ey);
} }
/************************************************************************* /*************************************************************************

View file

@ -207,15 +207,7 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
} }
else{ else{
/* If padding is unnecessary, then copy the input image. */ /* If padding is unnecessary, then copy the input image. */
pdata = (unsigned char *)malloc(iw*ih); pdata = (unsigned char *)g_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);
}
memcpy(pdata, idata, iw*ih); memcpy(pdata, idata, iw*ih);
pw = iw; pw = iw;
ph = ih; ph = ih;
@ -244,7 +236,7 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
free_dir2rad(dir2rad); free_dir2rad(dir2rad);
free_dftwaves(dftwaves); free_dftwaves(dftwaves);
free_rotgrids(dftgrids); free_rotgrids(dftgrids);
free(pdata); g_free(pdata);
return(ret); return(ret);
} }
/* Deallocate working memories. */ /* Deallocate working memories. */
@ -268,11 +260,11 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
lfsparms->dirbin_grid_w, lfsparms->dirbin_grid_h, lfsparms->dirbin_grid_w, lfsparms->dirbin_grid_h,
RELATIVE2CENTER))){ RELATIVE2CENTER))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(pdata); g_free(pdata);
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free(high_curve_map); g_free(high_curve_map);
return(ret); return(ret);
} }
@ -281,11 +273,11 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
pdata, pw, ph, direction_map, mw, mh, pdata, pw, ph, direction_map, mw, mh,
dirbingrids, lfsparms))){ dirbingrids, lfsparms))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(pdata); g_free(pdata);
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free(high_curve_map); g_free(high_curve_map);
free_rotgrids(dirbingrids); free_rotgrids(dirbingrids);
return(ret); return(ret);
} }
@ -297,12 +289,12 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
/* the input image, then ERROR. */ /* the input image, then ERROR. */
if((iw != bw) || (ih != bh)){ if((iw != bw) || (ih != bh)){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(pdata); g_free(pdata);
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free(high_curve_map); g_free(high_curve_map);
free(bdata); g_free(bdata);
fprintf(stderr, "ERROR : lfs_detect_minutiae_V2 :"); fprintf(stderr, "ERROR : lfs_detect_minutiae_V2 :");
fprintf(stderr,"binary image has bad dimensions : %d, %d\n", fprintf(stderr,"binary image has bad dimensions : %d, %d\n",
bw, bh); bw, bh);
@ -332,12 +324,12 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
direction_map, low_flow_map, high_curve_map, direction_map, low_flow_map, high_curve_map,
mw, mh, lfsparms))){ mw, mh, lfsparms))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(pdata); g_free(pdata);
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free(high_curve_map); g_free(high_curve_map);
free(bdata); g_free(bdata);
return(ret); return(ret);
} }
@ -349,12 +341,12 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
direction_map, low_flow_map, high_curve_map, mw, mh, direction_map, low_flow_map, high_curve_map, mw, mh,
lfsparms))){ lfsparms))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(pdata); g_free(pdata);
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free(high_curve_map); g_free(high_curve_map);
free(bdata); g_free(bdata);
free_minutiae(minutiae); free_minutiae(minutiae);
return(ret); return(ret);
} }
@ -370,11 +362,11 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
if((ret = count_minutiae_ridges(minutiae, bdata, iw, ih, lfsparms))){ if((ret = count_minutiae_ridges(minutiae, bdata, iw, ih, lfsparms))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(pdata); g_free(pdata);
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free(high_curve_map); g_free(high_curve_map);
free_minutiae(minutiae); free_minutiae(minutiae);
return(ret); return(ret);
} }
@ -393,7 +385,7 @@ int lfs_detect_minutiae_V2(MINUTIAE **ominutiae,
gray2bin(1, 255, 0, bdata, iw, ih); gray2bin(1, 255, 0, bdata, iw, ih);
/* Deallocate working memory. */ /* Deallocate working memory. */
free(pdata); g_free(pdata);
/* Assign results to output pointers. */ /* Assign results to output pointers. */
*odmap = direction_map; *odmap = direction_map;

View file

@ -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"); fprintf(stderr, "ERROR : dft_dir_powers : DFT grids must be square\n");
return(-90); return(-90);
} }
rowsums = (int *)malloc(dftgrids->grid_w * sizeof(int)); rowsums = (int *)g_malloc(dftgrids->grid_w * sizeof(int));
if(rowsums == (int *)NULL){
fprintf(stderr, "ERROR : dft_dir_powers : malloc : rowsums\n");
return(-91);
}
memset(rowsums, 0, dftgrids->grid_w * sizeof(int)); memset(rowsums, 0, dftgrids->grid_w * sizeof(int));
/* Foreach direction ... */ /* Foreach direction ... */
@ -135,7 +131,7 @@ int dft_dir_powers(double **powers, unsigned char *pdata,
} }
/* Deallocate working memory. */ /* Deallocate working memory. */
free(rowsums); g_free(rowsums);
return(0); return(0);
} }
@ -355,11 +351,7 @@ int sort_dft_waves(int *wis, const double *powmaxs, const double *pownorms,
double *pownorms2; double *pownorms2;
/* Allocate normalized power^2 array */ /* Allocate normalized power^2 array */
pownorms2 = (double *)malloc(nstats * sizeof(double)); pownorms2 = (double *)g_malloc(nstats * sizeof(double));
if(pownorms2 == (double *)NULL){
fprintf(stderr, "ERROR : sort_dft_waves : malloc : pownorms2\n");
return(-100);
}
for(i = 0; i < nstats; i++){ for(i = 0; i < nstats; i++){
/* Wis will hold the sorted statistic indices when all is done. */ /* 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); bubble_sort_double_dec_2(pownorms2, wis, nstats);
/* Deallocate the working memory. */ /* Deallocate the working memory. */
free(pownorms2); g_free(pownorms2);
return(0); return(0);
} }

View file

@ -72,9 +72,9 @@ of the software.
*************************************************************************/ *************************************************************************/
void free_dir2rad(DIR2RAD *dir2rad) void free_dir2rad(DIR2RAD *dir2rad)
{ {
free(dir2rad->cos); g_free(dir2rad->cos);
free(dir2rad->sin); g_free(dir2rad->sin);
free(dir2rad); g_free(dir2rad);
} }
/************************************************************************* /*************************************************************************
@ -90,12 +90,12 @@ void free_dftwaves(DFTWAVES *dftwaves)
int i; int i;
for(i = 0; i < dftwaves->nwaves; i++){ for(i = 0; i < dftwaves->nwaves; i++){
free(dftwaves->waves[i]->cos); g_free(dftwaves->waves[i]->cos);
free(dftwaves->waves[i]->sin); g_free(dftwaves->waves[i]->sin);
free(dftwaves->waves[i]); g_free(dftwaves->waves[i]);
} }
free(dftwaves->waves); g_free(dftwaves->waves);
free(dftwaves); g_free(dftwaves);
} }
/************************************************************************* /*************************************************************************
@ -111,9 +111,9 @@ void free_rotgrids(ROTGRIDS *rotgrids)
int i; int i;
for(i = 0; i < rotgrids->ngrids; i++) for(i = 0; i < rotgrids->ngrids; i++)
free(rotgrids->grids[i]); g_free(rotgrids->grids[i]);
free(rotgrids->grids); g_free(rotgrids->grids);
free(rotgrids); g_free(rotgrids);
} }
/************************************************************************* /*************************************************************************
@ -129,8 +129,8 @@ void free_dir_powers(double **powers, const int nwaves)
int w; int w;
for(w = 0; w < nwaves; w++) for(w = 0; w < nwaves; w++)
free(powers[w]); g_free(powers[w]);
free(powers); g_free(powers);
} }

View file

@ -134,11 +134,11 @@ int get_minutiae(MINUTIAE **ominutiae, int **oquality_map,
direction_map, low_contrast_map, direction_map, low_contrast_map,
low_flow_map, high_curve_map, map_w, map_h))){ low_flow_map, high_curve_map, map_w, map_h))){
free_minutiae(minutiae); free_minutiae(minutiae);
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free(high_curve_map); g_free(high_curve_map);
free(bdata); g_free(bdata);
return(ret); return(ret);
} }
@ -147,12 +147,12 @@ int get_minutiae(MINUTIAE **ominutiae, int **oquality_map,
lfsparms->blocksize, lfsparms->blocksize,
idata, iw, ih, id, ppmm))){ idata, iw, ih, id, ppmm))){
free_minutiae(minutiae); free_minutiae(minutiae);
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free(high_curve_map); g_free(high_curve_map);
free(quality_map); g_free(quality_map);
free(bdata); g_free(bdata);
return(ret); return(ret);
} }

View file

@ -191,11 +191,7 @@ int pad_uchar_image(unsigned char **optr, int *ow, int *oh,
psize = pw * ph; psize = pw * ph;
/* Allocate padded image */ /* Allocate padded image */
pdata = (unsigned char *)malloc(psize * sizeof(unsigned char)); pdata = (unsigned char *)g_malloc(psize * sizeof(unsigned char));
if(pdata == (unsigned char *)NULL){
fprintf(stderr, "ERROR : pad_uchar_image : malloc : pdata\n");
return(-160);
}
/* Initialize values to a constant PAD value */ /* Initialize values to a constant PAD value */
memset(pdata, pad_value, psize); 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 number of transitions seen > than threshold (ex. 2) ... */
if(trans > lfsparms->maxtrans){ if(trans > lfsparms->maxtrans){
/* Deallocate the line segment's coordinate lists. */ /* Deallocate the line segment's coordinate lists. */
free(x_list); g_free(x_list);
free(y_list); g_free(y_list);
/* Return free path to be FALSE. */ /* Return free path to be FALSE. */
return(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 */ /* If we get here we did not exceed the maximum allowable number */
/* of transitions. So, deallocate the line segment's coordinate lists. */ /* of transitions. So, deallocate the line segment's coordinate lists. */
free(x_list); g_free(x_list);
free(y_list); g_free(y_list);
/* Return free path to be TRUE. */ /* Return free path to be TRUE. */
return(TRUE); return(TRUE);

View file

@ -91,33 +91,16 @@ int init_dir2rad(DIR2RAD **optr, const int ndirs)
double cs, sn; double cs, sn;
/* Allocate structure */ /* Allocate structure */
dir2rad = (DIR2RAD *)malloc(sizeof(DIR2RAD)); dir2rad = (DIR2RAD *)g_malloc(sizeof(DIR2RAD));
if(dir2rad == (DIR2RAD *)NULL){
fprintf(stderr, "ERROR : init_dir2rad : malloc : dir2rad\n");
return(-10);
}
/* Assign number of directions */ /* Assign number of directions */
dir2rad->ndirs = ndirs; dir2rad->ndirs = ndirs;
/* Allocate cosine vector */ /* Allocate cosine vector */
dir2rad->cos = (double *)malloc(ndirs * sizeof(double)); dir2rad->cos = (double *)g_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);
}
/* Allocate sine vector */ /* Allocate sine vector */
dir2rad->sin = (double *)malloc(ndirs * sizeof(double)); dir2rad->sin = (double *)g_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);
}
/* Pi_factor sets the period of the trig functions to NDIRS units in x. */ /* 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... */ /* 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; double *cptr, *sptr;
/* Allocate structure */ /* Allocate structure */
dftwaves = (DFTWAVES *)malloc(sizeof(DFTWAVES)); dftwaves = (DFTWAVES *)g_malloc(sizeof(DFTWAVES));
if(dftwaves == (DFTWAVES *)NULL){
fprintf(stderr, "ERROR : init_dftwaves : malloc : dftwaves\n");
return(-20);
}
/* Set number of DFT waves */ /* Set number of DFT waves */
dftwaves->nwaves = nwaves; dftwaves->nwaves = nwaves;
@ -178,10 +157,10 @@ int init_dftwaves(DFTWAVES **optr, const double *dft_coefs,
dftwaves->wavelen = blocksize; dftwaves->wavelen = blocksize;
/* Allocate list of wave pointers */ /* Allocate list of wave pointers */
dftwaves->waves = (DFTWAVE **)malloc(nwaves * sizeof(DFTWAVE *)); dftwaves->waves = (DFTWAVE **)g_malloc(nwaves * sizeof(DFTWAVE *));
if(dftwaves == (DFTWAVES *)NULL){ if(dftwaves == (DFTWAVES *)NULL){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(dftwaves); g_free(dftwaves);
fprintf(stderr, "ERROR : init_dftwaves : malloc : dftwaves->waves\n"); fprintf(stderr, "ERROR : init_dftwaves : malloc : dftwaves->waves\n");
return(-21); return(-21);
} }
@ -194,53 +173,11 @@ int init_dftwaves(DFTWAVES **optr, const double *dft_coefs,
/* Foreach of 4 DFT frequency coef ... */ /* Foreach of 4 DFT frequency coef ... */
for (i = 0; i < nwaves; ++i) { for (i = 0; i < nwaves; ++i) {
/* Allocate wave structure */ /* Allocate wave structure */
dftwaves->waves[i] = (DFTWAVE *)malloc(sizeof(DFTWAVE)); dftwaves->waves[i] = (DFTWAVE *)g_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);
}
/* Allocate cosine vector */ /* Allocate cosine vector */
dftwaves->waves[i]->cos = (double *)malloc(blocksize * sizeof(double)); dftwaves->waves[i]->cos = (double *)g_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);
}
/* Allocate sine vector */ /* Allocate sine vector */
dftwaves->waves[i]->sin = (double *)malloc(blocksize * sizeof(double)); dftwaves->waves[i]->sin = (double *)g_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);
}
/* Assign pointer nicknames */ /* Assign pointer nicknames */
cptr = dftwaves->waves[i]->cos; 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; double pad;
/* Allocate structure */ /* Allocate structure */
rotgrids = (ROTGRIDS *)malloc(sizeof(ROTGRIDS)); rotgrids = (ROTGRIDS *)g_malloc(sizeof(ROTGRIDS));
if(rotgrids == (ROTGRIDS *)NULL){
fprintf(stderr, "ERROR : init_rotgrids : malloc : rotgrids\n");
return(-30);
}
/* Set rotgrid attributes */ /* Set rotgrid attributes */
rotgrids->ngrids = ndirs; rotgrids->ngrids = ndirs;
@ -474,7 +407,7 @@ int init_rotgrids(ROTGRIDS **optr, const int iw, const int ih, const int ipad,
fprintf(stderr, fprintf(stderr,
"ERROR : init_rotgrids : Illegal relative flag : %d\n", "ERROR : init_rotgrids : Illegal relative flag : %d\n",
relative2); relative2);
free(rotgrids); g_free(rotgrids);
return(-31); 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(ipad < grid_pad){
/* If input pad is NOT large enough, then ERROR. */ /* If input pad is NOT large enough, then ERROR. */
fprintf(stderr, "ERROR : init_rotgrids : Pad passed is too small\n"); fprintf(stderr, "ERROR : init_rotgrids : Pad passed is too small\n");
free(rotgrids); g_free(rotgrids);
return(-32); return(-32);
} }
/* Otherwise, use the specified input pad in computing grid offsets. */ /* 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; cy = (grid_h-1)/(double)2.0;
/* Allocate list of rotgrid pointers */ /* Allocate list of rotgrid pointers */
rotgrids->grids = (int **)malloc(ndirs * sizeof(int *)); rotgrids->grids = (int **)g_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);
}
/* Pi_offset is the offset in radians from which angles are to begin. */ /* Pi_offset is the offset in radians from which angles are to begin. */
pi_offset = start_dir_angle; 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) { dir < ndirs; dir++, theta += pi_incr) {
/* Allocate a rotgrid */ /* Allocate a rotgrid */
rotgrids->grids[dir] = (int *)malloc(grid_size * sizeof(int)); rotgrids->grids[dir] = (int *)g_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);
}
/* Set pointer to current grid */ /* Set pointer to current grid */
grid = rotgrids->grids[dir]; grid = rotgrids->grids[dir];
@ -635,24 +552,11 @@ int alloc_dir_powers(double ***opowers, const int nwaves, const int ndirs)
double **powers; double **powers;
/* Allocate list of double pointers to hold power vectors */ /* Allocate list of double pointers to hold power vectors */
powers = (double **)malloc(nwaves * sizeof(double*)); powers = (double **)g_malloc(nwaves * sizeof(double *));
if(powers == (double **)NULL){
fprintf(stderr, "ERROR : alloc_dir_powers : malloc : powers\n");
return(-40);
}
/* Foreach DFT wave ... */ /* Foreach DFT wave ... */
for(w = 0; w < nwaves; w++){ for(w = 0; w < nwaves; w++){
/* Allocate power vector for all directions */ /* Allocate power vector for all directions */
powers[w] = (double *)malloc(ndirs * sizeof(double)); powers[w] = (double *)g_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);
}
} }
*opowers = powers; *opowers = powers;
@ -697,41 +601,16 @@ int alloc_power_stats(int **owis, double **opowmaxs, int **opowmax_dirs,
ASSERT_SIZE_MUL(nstats, sizeof(double)); ASSERT_SIZE_MUL(nstats, sizeof(double));
/* Allocate DFT wave index vector */ /* Allocate DFT wave index vector */
wis = (int *)malloc(nstats * sizeof(int)); wis = (int *)g_malloc(nstats * sizeof(int));
if(wis == (int *)NULL){
fprintf(stderr, "ERROR : alloc_power_stats : malloc : wis\n");
return(-50);
}
/* Allocate max power vector */ /* Allocate max power vector */
powmaxs = (double *)malloc(nstats * sizeof(double)); powmaxs = (double *)g_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);
}
/* Allocate max power direction vector */ /* Allocate max power direction vector */
powmax_dirs = (int *)malloc(nstats * sizeof(int)); powmax_dirs = (int *)g_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);
}
/* Allocate normalized power vector */ /* Allocate normalized power vector */
pownorms = (double *)malloc(nstats * sizeof(double)); pownorms = (double *)g_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);
}
*owis = wis; *owis = wis;
*opowmaxs = powmaxs; *opowmaxs = powmaxs;

View file

@ -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); asize = max(abs(x2-x1)+2, abs(y2-y1)+2);
/* Allocate x and y-pixel coordinate lists to length 'asize'. */ /* Allocate x and y-pixel coordinate lists to length 'asize'. */
x_list = (int *)malloc(asize*sizeof(int)); x_list = (int *)g_malloc(asize * sizeof(int));
if(x_list == (int *)NULL){ y_list = (int *)g_malloc(asize * sizeof(int));
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);
}
/* Compute delta x and y. */ /* Compute delta x and y. */
dx = x2 - x1; dx = x2 - x1;
@ -190,8 +181,8 @@ int line_points(int **ox_list, int **oy_list, int *onum,
if(i >= asize){ if(i >= asize){
fprintf(stderr, "ERROR : line_points : coord list overflow\n"); fprintf(stderr, "ERROR : line_points : coord list overflow\n");
free(x_list); g_free(x_list);
free(y_list); g_free(y_list);
return(-412); return(-412);
} }

View file

@ -443,7 +443,7 @@ int is_loop_clockwise(const int *contour_x, const int *contour_y,
ret = is_chain_clockwise(chain, nchain, default_ret); ret = is_chain_clockwise(chain, nchain, default_ret);
/* Free the chain code and return result. */ /* Free the chain code and return result. */
free(chain); g_free(chain);
return(ret); return(ret);
} }

View file

@ -154,14 +154,14 @@ int gen_image_maps(int **odmap, int **olcmap, int **olfmap, int **ohcmap,
&low_flow_map, blkoffs, mw, mh, &low_flow_map, blkoffs, mw, mh,
pdata, pw, ph, dftwaves, dftgrids, lfsparms))){ pdata, pw, ph, dftwaves, dftgrids, lfsparms))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(blkoffs); g_free(blkoffs);
return(ret); return(ret);
} }
if((ret = morph_TF_map(low_flow_map, mw, mh, lfsparms))){ if((ret = morph_TF_map(low_flow_map, mw, mh, lfsparms))){
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
return(ret); 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. */ /* 5. Interpolate INVALID direction blocks with their valid neighbors. */
if((ret = interpolate_direction_map(direction_map, low_contrast_map, if((ret = interpolate_direction_map(direction_map, low_contrast_map,
mw, mh, lfsparms))){ mw, mh, lfsparms))){
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
return(ret); 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. */ /* 9. Generate High Curvature Map from interpolated Direction Map. */
if((ret = gen_high_curve_map(&high_curve_map, direction_map, mw, mh, if((ret = gen_high_curve_map(&high_curve_map, direction_map, mw, mh,
lfsparms))){ lfsparms))){
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
return(ret); return(ret);
} }
/* Deallocate working memory. */ /* Deallocate working memory. */
free(blkoffs); g_free(blkoffs);
*odmap = direction_map; *odmap = direction_map;
*olcmap = low_contrast_map; *olcmap = low_contrast_map;
@ -276,44 +276,26 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap,
bsize = mw * mh; bsize = mw * mh;
/* Allocate Direction Map memory */ /* Allocate Direction Map memory */
direction_map = (int *)malloc(bsize * sizeof(int)); direction_map = (int *)g_malloc(bsize * sizeof(int));
if(direction_map == (int *)NULL){
fprintf(stderr,
"ERROR : gen_initial_maps : malloc : direction_map\n");
return(-550);
}
/* Initialize the Direction Map to INVALID (-1). */ /* Initialize the Direction Map to INVALID (-1). */
memset(direction_map, INVALID_DIR, bsize * sizeof(int)); memset(direction_map, INVALID_DIR, bsize * sizeof(int));
/* Allocate Low Contrast Map memory */ /* Allocate Low Contrast Map memory */
low_contrast_map = (int *)malloc(bsize * sizeof(int)); low_contrast_map = (int *)g_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);
}
/* Initialize the Low Contrast Map to FALSE (0). */ /* Initialize the Low Contrast Map to FALSE (0). */
memset(low_contrast_map, 0, bsize * sizeof(int)); memset(low_contrast_map, 0, bsize * sizeof(int));
/* Allocate Low Ridge Flow Map memory */ /* Allocate Low Ridge Flow Map memory */
low_flow_map = (int *)malloc(bsize * sizeof(int)); low_flow_map = (int *)g_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);
}
/* Initialize the Low Flow Map to FALSE (0). */ /* Initialize the Low Flow Map to FALSE (0). */
memset(low_flow_map, 0, bsize * sizeof(int)); memset(low_flow_map, 0, bsize * sizeof(int));
/* Allocate DFT directional power vectors */ /* Allocate DFT directional power vectors */
if((ret = alloc_dir_powers(&powers, dftwaves->nwaves, dftgrids->ngrids))){ if((ret = alloc_dir_powers(&powers, dftwaves->nwaves, dftgrids->ngrids))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
return(ret); 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, if((ret = alloc_power_stats(&wis, &powmaxs, &powmax_dirs,
&pownorms, nstats))){ &pownorms, nstats))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free_dir_powers(powers, dftwaves->nwaves); free_dir_powers(powers, dftwaves->nwaves);
return(ret); return(ret);
} }
@ -364,14 +346,14 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap,
pdata, pw, ph, lfsparms))){ pdata, pw, ph, lfsparms))){
/* If system error ... */ /* If system error ... */
if(ret < 0){ if(ret < 0){
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free_dir_powers(powers, dftwaves->nwaves); free_dir_powers(powers, dftwaves->nwaves);
free(wis); g_free(wis);
free(powmaxs); g_free(powmaxs);
free(powmax_dirs); g_free(powmax_dirs);
free(pownorms); g_free(pownorms);
return(ret); 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, if((ret = dft_dir_powers(powers, pdata, low_contrast_offset, pw, ph,
dftwaves, dftgrids))){ dftwaves, dftgrids))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free_dir_powers(powers, dftwaves->nwaves); free_dir_powers(powers, dftwaves->nwaves);
free(wis); g_free(wis);
free(powmaxs); g_free(powmaxs);
free(powmax_dirs); g_free(powmax_dirs);
free(pownorms); g_free(pownorms);
return(ret); 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, if((ret = dft_power_stats(wis, powmaxs, powmax_dirs, pownorms, powers,
1, dftwaves->nwaves, dftgrids->ngrids))){ 1, dftwaves->nwaves, dftgrids->ngrids))){
/* Free memory allocated to this point. */ /* Free memory allocated to this point. */
free(direction_map); g_free(direction_map);
free(low_contrast_map); g_free(low_contrast_map);
free(low_flow_map); g_free(low_flow_map);
free_dir_powers(powers, dftwaves->nwaves); free_dir_powers(powers, dftwaves->nwaves);
free(wis); g_free(wis);
free(powmaxs); g_free(powmaxs);
free(powmax_dirs); g_free(powmax_dirs);
free(pownorms); g_free(pownorms);
return(ret); return(ret);
} }
@ -452,10 +434,10 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap,
/* Deallocate working memory */ /* Deallocate working memory */
free_dir_powers(powers, dftwaves->nwaves); free_dir_powers(powers, dftwaves->nwaves);
free(wis); g_free(wis);
free(powmaxs); g_free(powmaxs);
free(powmax_dirs); g_free(powmax_dirs);
free(pownorms); g_free(pownorms);
*odmap = direction_map; *odmap = direction_map;
*olcmap = low_contrast_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. */ /* Allocate output (interpolated) Direction Map. */
ASSERT_SIZE_MUL(mw, mh); ASSERT_SIZE_MUL(mw, mh);
ASSERT_SIZE_MUL(mw * mh, sizeof(int)); ASSERT_SIZE_MUL(mw * mh, sizeof(int));
omap = (int *)malloc(mw*mh*sizeof(int)); omap = (int *)g_malloc(mw * mh * sizeof(int));
if(omap == (int *)NULL){
fprintf(stderr,
"ERROR : interpolate_direction_map : malloc : omap\n");
return(-520);
}
/* Set pointers to the first block in the maps. */ /* Set pointers to the first block in the maps. */
dptr = direction_map; 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. */ /* Copy the interpolated directions into the input map. */
memcpy(direction_map, omap, mw*mh*sizeof(int)); memcpy(direction_map, omap, mw*mh*sizeof(int));
/* Deallocate the working memory. */ /* Deallocate the working memory. */
free(omap); g_free(omap);
/* Return normally. */ /* Return normally. */
return(0); return(0);
@ -680,18 +657,9 @@ int morph_TF_map(int *tfmap, const int mw, const int mh,
ASSERT_INT_MUL(mw, mh); ASSERT_INT_MUL(mw, mh);
/* Convert TRUE/FALSE map into a binary byte image. */ /* Convert TRUE/FALSE map into a binary byte image. */
cimage = (unsigned char *)malloc(mw*mh); cimage = (unsigned char *)g_malloc(mw * mh);
if(cimage == (unsigned char *)NULL){
fprintf(stderr, "ERROR : morph_TF_map : malloc : cimage\n");
return(-660);
}
mimage = (unsigned char *)malloc(mw*mh); mimage = (unsigned char *)g_malloc(mw * mh);
if(mimage == (unsigned char *)NULL){
free(cimage);
fprintf(stderr, "ERROR : morph_TF_map : malloc : mimage\n");
return(-661);
}
cptr = cimage; cptr = cimage;
mptr = tfmap; mptr = tfmap;
@ -710,8 +678,8 @@ int morph_TF_map(int *tfmap, const int mw, const int mh,
*mptr++ = *cptr++; *mptr++ = *cptr++;
} }
free(cimage); g_free(cimage);
free(mimage); g_free(mimage);
return(0); 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);
ASSERT_SIZE_MUL(iw * ih, sizeof(int)); ASSERT_SIZE_MUL(iw * ih, sizeof(int));
pmap = (int *)malloc(iw*ih*sizeof(int)); pmap = (int *)g_malloc(iw * ih * sizeof(int));
if(pmap == (int *)NULL){
fprintf(stderr, "ERROR : pixelize_map : malloc : pmap\n");
return(-590);
}
if((ret = block_offsets(&blkoffs, &bw, &bh, iw, ih, 0, blocksize))){ if((ret = block_offsets(&blkoffs, &bw, &bh, iw, ih, 0, blocksize))){
free(pmap); g_free(pmap);
return(ret); return(ret);
} }
if((bw != mw) || (bh != mh)){ if((bw != mw) || (bh != mh)){
free(blkoffs); g_free(blkoffs);
free(pmap); g_free(pmap);
fprintf(stderr, fprintf(stderr,
"ERROR : pixelize_map : block dimensions do not match\n"); "ERROR : pixelize_map : block dimensions do not match\n");
return(-591); return(-591);
@ -777,7 +741,7 @@ int pixelize_map(int **omap, const int iw, const int ih,
} }
/* Deallocate working memory. */ /* Deallocate working memory. */
free(blkoffs); g_free(blkoffs);
/* Assign pixelized map to output pointer. */ /* Assign pixelized map to output pointer. */
*omap = pmap; *omap = pmap;
@ -910,12 +874,7 @@ int gen_high_curve_map(int **ohcmap, int *direction_map,
/* Allocate High Curvature Map. */ /* Allocate High Curvature Map. */
ASSERT_SIZE_MUL(mapsize, sizeof(int)); ASSERT_SIZE_MUL(mapsize, sizeof(int));
high_curve_map = (int *)malloc(mapsize * sizeof(int)); high_curve_map = (int *)g_malloc(mapsize * sizeof(int));
if(high_curve_map == (int *)NULL){
fprintf(stderr,
"ERROR: gen_high_curve_map : malloc : high_curve_map\n");
return(-530);
}
/* Initialize High Curvature Map to FALSE (0). */ /* Initialize High Curvature Map to FALSE (0). */
memset(high_curve_map, 0, mapsize*sizeof(int)); memset(high_curve_map, 0, mapsize*sizeof(int));

View file

@ -118,16 +118,8 @@ int alloc_minutiae(MINUTIAE **ominutiae, const int DEFAULT_BOZORTH_MINUTIAE)
{ {
MINUTIAE *minutiae; MINUTIAE *minutiae;
minutiae = (MINUTIAE *)malloc(sizeof(MINUTIAE)); minutiae = (MINUTIAE *)g_malloc(sizeof(MINUTIAE));
if(minutiae == (MINUTIAE *)NULL){ minutiae->list = (MINUTIA **)g_malloc(DEFAULT_BOZORTH_MINUTIAE * sizeof(MINUTIA *));
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->alloc = DEFAULT_BOZORTH_MINUTIAE; minutiae->alloc = DEFAULT_BOZORTH_MINUTIAE;
minutiae->num = 0; 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) int realloc_minutiae(MINUTIAE *minutiae, const int incr_minutiae)
{ {
minutiae->alloc += incr_minutiae; minutiae->alloc += incr_minutiae;
minutiae->list = (MINUTIA **)realloc(minutiae->list, minutiae->list = (MINUTIA **)g_realloc(minutiae->list,
minutiae->alloc * sizeof(MINUTIA *)); minutiae->alloc * sizeof(MINUTIA *));
if(minutiae->list == (MINUTIA **)NULL){
fprintf(stderr, "ERROR : realloc_minutiae : realloc : minutiae->list\n");
exit(-432);
}
return(0); 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, if((ret = pixelize_map(&plow_flow_map, iw, ih, low_flow_map, mw, mh,
lfsparms->blocksize))){ lfsparms->blocksize))){
free(pdirection_map); g_free(pdirection_map);
return(ret); return(ret);
} }
if((ret = pixelize_map(&phigh_curve_map, iw, ih, high_curve_map, mw, mh, if((ret = pixelize_map(&phigh_curve_map, iw, ih, high_curve_map, mw, mh,
lfsparms->blocksize))){ lfsparms->blocksize))){
free(pdirection_map); g_free(pdirection_map);
free(plow_flow_map); g_free(plow_flow_map);
return(ret); return(ret);
} }
if((ret = scan4minutiae_horizontally_V2(minutiae, bdata, iw, ih, if((ret = scan4minutiae_horizontally_V2(minutiae, bdata, iw, ih,
pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){ pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){
free(pdirection_map); g_free(pdirection_map);
free(plow_flow_map); g_free(plow_flow_map);
free(phigh_curve_map); g_free(phigh_curve_map);
return(ret); return(ret);
} }
if((ret = scan4minutiae_vertically_V2(minutiae, bdata, iw, ih, if((ret = scan4minutiae_vertically_V2(minutiae, bdata, iw, ih,
pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){ pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){
free(pdirection_map); g_free(pdirection_map);
free(plow_flow_map); g_free(plow_flow_map);
free(phigh_curve_map); g_free(phigh_curve_map);
return(ret); return(ret);
} }
/* Deallocate working memories. */ /* Deallocate working memories. */
free(pdirection_map); g_free(pdirection_map);
free(plow_flow_map); g_free(plow_flow_map);
free(phigh_curve_map); g_free(phigh_curve_map);
/* Return normally. */ /* Return normally. */
return(0); 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 */ /* Allocate a list of integers to hold 1-D image pixel offsets */
/* for each of the 2-D minutia coordinate points. */ /* for each of the 2-D minutia coordinate points. */
ranks = (int *)malloc(minutiae->num * sizeof(int)); ranks = (int *)g_malloc(minutiae->num * sizeof(int));
if(ranks == (int *)NULL){
fprintf(stderr, "ERROR : sort_minutiae_y_x : malloc : ranks\n");
return(-310);
}
/* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */ /* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */
for(i = 0; i < minutiae->num; i++) 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. */ /* Get sorted order of minutiae. */
if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){ if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){
free(ranks); g_free(ranks);
return(ret); return(ret);
} }
/* Allocate new MINUTIA list to hold sorted minutiae. */ /* Allocate new MINUTIA list to hold sorted minutiae. */
newlist = (MINUTIA **)malloc(minutiae->num * sizeof(MINUTIA *)); newlist = (MINUTIA **)g_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);
}
/* Put minutia into sorted order in new list. */ /* Put minutia into sorted order in new list. */
for(i = 0; i < minutiae->num; i++) for(i = 0; i < minutiae->num; i++)
newlist[i] = minutiae->list[order[i]]; newlist[i] = minutiae->list[order[i]];
/* Deallocate non-sorted list of minutia pointers. */ /* Deallocate non-sorted list of minutia pointers. */
free(minutiae->list); g_free(minutiae->list);
/* Assign new sorted list of minutia to minutiae list. */ /* Assign new sorted list of minutia to minutiae list. */
minutiae->list = newlist; minutiae->list = newlist;
/* Free the working memories supporting the sort. */ /* Free the working memories supporting the sort. */
free(order); g_free(order);
free(ranks); g_free(ranks);
/* Return normally. */ /* Return normally. */
return(0); 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 */ /* Allocate a list of integers to hold 1-D image pixel offsets */
/* for each of the 2-D minutia coordinate points. */ /* for each of the 2-D minutia coordinate points. */
ranks = (int *)malloc(minutiae->num * sizeof(int)); ranks = (int *)g_malloc(minutiae->num * sizeof(int));
if(ranks == (int *)NULL){
fprintf(stderr, "ERROR : sort_minutiae_x_y : malloc : ranks\n");
return(-440);
}
/* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */ /* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */
for(i = 0; i < minutiae->num; i++) 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. */ /* Get sorted order of minutiae. */
if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){ if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){
free(ranks); g_free(ranks);
return(ret); return(ret);
} }
/* Allocate new MINUTIA list to hold sorted minutiae. */ /* Allocate new MINUTIA list to hold sorted minutiae. */
newlist = (MINUTIA **)malloc(minutiae->num * sizeof(MINUTIA *)); newlist = (MINUTIA **)g_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);
}
/* Put minutia into sorted order in new list. */ /* Put minutia into sorted order in new list. */
for(i = 0; i < minutiae->num; i++) for(i = 0; i < minutiae->num; i++)
newlist[i] = minutiae->list[order[i]]; newlist[i] = minutiae->list[order[i]];
/* Deallocate non-sorted list of minutia pointers. */ /* Deallocate non-sorted list of minutia pointers. */
free(minutiae->list); g_free(minutiae->list);
/* Assign new sorted list of minutia to minutiae list. */ /* Assign new sorted list of minutia to minutiae list. */
minutiae->list = newlist; minutiae->list = newlist;
/* Free the working memories supporting the sort. */ /* Free the working memories supporting the sort. */
free(order); g_free(order);
free(ranks); g_free(ranks);
/* Return normally. */ /* Return normally. */
return(0); return(0);
@ -764,12 +732,7 @@ int create_minutia(MINUTIA **ominutia, const int x_loc, const int y_loc,
MINUTIA *minutia; MINUTIA *minutia;
/* Allocate a minutia structure. */ /* Allocate a minutia structure. */
minutia = (MINUTIA *)malloc(sizeof(MINUTIA)); minutia = (MINUTIA *)g_malloc(sizeof(MINUTIA));
/* If allocation error... */
if(minutia == (MINUTIA *)NULL){
fprintf(stderr, "ERROR : create_minutia : malloc : minutia\n");
return(-230);
}
/* Assign minutia structure attributes. */ /* Assign minutia structure attributes. */
minutia->x = x_loc; minutia->x = x_loc;
@ -807,10 +770,10 @@ void free_minutiae(MINUTIAE *minutiae)
for(i = 0; i < minutiae->num; i++) for(i = 0; i < minutiae->num; i++)
free_minutia(minutiae->list[i]); free_minutia(minutiae->list[i]);
/* Deallocate list of minutia pointers. */ /* Deallocate list of minutia pointers. */
free(minutiae->list); g_free(minutiae->list);
/* Deallocate the list structure. */ /* Deallocate the list structure. */
free(minutiae); g_free(minutiae);
} }
/************************************************************************* /*************************************************************************
@ -825,12 +788,12 @@ void free_minutia(MINUTIA *minutia)
{ {
/* Deallocate sublists. */ /* Deallocate sublists. */
if(minutia->nbrs != (int *)NULL) if(minutia->nbrs != (int *)NULL)
free(minutia->nbrs); g_free(minutia->nbrs);
if(minutia->ridge_counts != (int *)NULL) if(minutia->ridge_counts != (int *)NULL)
free(minutia->ridge_counts); g_free(minutia->ridge_counts);
/* Deallocate the minutia structure. */ /* Deallocate the minutia structure. */
free(minutia); g_free(minutia);
} }
/************************************************************************* /*************************************************************************

View file

@ -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);
ASSERT_SIZE_MUL(map_w * map_h, sizeof(int)); ASSERT_SIZE_MUL(map_w * map_h, sizeof(int));
QualMap = (int *)malloc(map_w * map_h * sizeof(int)); QualMap = (int *)g_malloc(map_w * map_h * sizeof(int));
if(QualMap == (int *)NULL){
fprintf(stderr, "ERROR : gen_quality_map : malloc : QualMap\n");
return(-2);
}
/* Foreach row of blocks in maps ... */ /* Foreach row of blocks in maps ... */
for(thisY=0; thisY<map_h; thisY++){ for(thisY=0; thisY<map_h; thisY++){
@ -287,14 +283,14 @@ int combined_minutia_quality(MINUTIAE *minutiae,
fprintf(stderr, "ERROR : combined_miutia_quality : "); fprintf(stderr, "ERROR : combined_miutia_quality : ");
fprintf(stderr, "unexpected quality map value %d ", qmap_value); fprintf(stderr, "unexpected quality map value %d ", qmap_value);
fprintf(stderr, "not in range [0..4]\n"); fprintf(stderr, "not in range [0..4]\n");
free(pquality_map); g_free(pquality_map);
return(-3); return(-3);
} }
minutia->reliability = reliability; minutia->reliability = reliability;
} }
/* NEW 05-08-2002 */ /* NEW 05-08-2002 */
free(pquality_map); g_free(pquality_map);
/* Return normally. */ /* Return normally. */
return(0); return(0);

View file

@ -380,7 +380,7 @@ int remove_hooks(MINUTIAE *minutiae,
if((deltadir = closest_dir_dist(minutia1->direction, if((deltadir = closest_dir_dist(minutia1->direction,
minutia2->direction, full_ndirs)) == minutia2->direction, full_ndirs)) ==
INVALID_DIR){ INVALID_DIR){
free(to_remove); g_free(to_remove);
fprintf(stderr, fprintf(stderr,
"ERROR : remove_hooks : INVALID direction\n"); "ERROR : remove_hooks : INVALID direction\n");
return(-641); return(-641);
@ -424,7 +424,7 @@ int remove_hooks(MINUTIAE *minutiae,
} }
/* If system error occurred during hook test ... */ /* If system error occurred during hook test ... */
else if (ret < 0){ else if (ret < 0){
free(to_remove); g_free(to_remove);
return(ret); return(ret);
} }
/* Otherwise, no hook found, so skip to next */ /* Otherwise, no hook found, so skip to next */
@ -474,14 +474,14 @@ int remove_hooks(MINUTIAE *minutiae,
if(to_remove[i]){ if(to_remove[i]){
/* Remove the minutia from the minutiae list. */ /* Remove the minutia from the minutiae list. */
if((ret = remove_minutia(i, minutiae))){ if((ret = remove_minutia(i, minutiae))){
free(to_remove); g_free(to_remove);
return(ret); return(ret);
} }
} }
} }
/* Deallocate flag list. */ /* Deallocate flag list. */
free(to_remove); g_free(to_remove);
/* Return normally. */ /* Return normally. */
return(0); return(0);
@ -641,7 +641,7 @@ int remove_islands_and_lakes(MINUTIAE *minutiae,
if((deltadir = closest_dir_dist(minutia1->direction, if((deltadir = closest_dir_dist(minutia1->direction,
minutia2->direction, full_ndirs)) == minutia2->direction, full_ndirs)) ==
INVALID_DIR){ INVALID_DIR){
free(to_remove); g_free(to_remove);
fprintf(stderr, fprintf(stderr,
"ERROR : remove_islands_and_lakes : INVALID direction\n"); "ERROR : remove_islands_and_lakes : INVALID direction\n");
return(-611); return(-611);
@ -673,7 +673,7 @@ int remove_islands_and_lakes(MINUTIAE *minutiae,
bdata, iw, ih))){ bdata, iw, ih))){
free_contour(loop_x, loop_y, free_contour(loop_x, loop_y,
loop_ex, loop_ey); loop_ex, loop_ey);
free(to_remove); g_free(to_remove);
return(ret); return(ret);
} }
/* Set to remove first minutia. */ /* Set to remove first minutia. */
@ -696,7 +696,7 @@ int remove_islands_and_lakes(MINUTIAE *minutiae,
} }
/* If ERROR while looking for island/lake ... */ /* If ERROR while looking for island/lake ... */
else if (ret < 0){ else if (ret < 0){
free(to_remove); g_free(to_remove);
return(ret); return(ret);
} }
else else
@ -741,14 +741,14 @@ int remove_islands_and_lakes(MINUTIAE *minutiae,
if(to_remove[i]){ if(to_remove[i]){
/* Remove the minutia from the minutiae list. */ /* Remove the minutia from the minutiae list. */
if((ret = remove_minutia(i, minutiae))){ if((ret = remove_minutia(i, minutiae))){
free(to_remove); g_free(to_remove);
return(ret); return(ret);
} }
} }
} }
/* Deallocate flag list. */ /* Deallocate flag list. */
free(to_remove); g_free(to_remove);
/* Return normally. */ /* Return normally. */
return(0); return(0);
@ -950,8 +950,8 @@ int remove_malformations(MINUTIAE *minutiae,
print2log("%d,%d RMMAL3 (%f)\n", print2log("%d,%d RMMAL3 (%f)\n",
minutia->x, minutia->y, ratio); minutia->x, minutia->y, ratio);
if((ret = remove_minutia(i, minutiae))){ if((ret = remove_minutia(i, minutiae))){
free(x_list); g_free(x_list);
free(y_list); g_free(y_list);
/* If system error, return error code. */ /* If system error, return error code. */
return(ret); return(ret);
} }
@ -961,8 +961,8 @@ int remove_malformations(MINUTIAE *minutiae,
} }
} }
free(x_list); g_free(x_list);
free(y_list); g_free(y_list);
} }
} }
@ -1447,7 +1447,7 @@ int remove_overlaps(MINUTIAE *minutiae,
if((deltadir = closest_dir_dist(minutia1->direction, if((deltadir = closest_dir_dist(minutia1->direction,
minutia2->direction, full_ndirs)) == minutia2->direction, full_ndirs)) ==
INVALID_DIR){ INVALID_DIR){
free(to_remove); g_free(to_remove);
fprintf(stderr, fprintf(stderr,
"ERROR : remove_overlaps : INVALID direction\n"); "ERROR : remove_overlaps : INVALID direction\n");
return(-651); return(-651);
@ -1546,14 +1546,14 @@ int remove_overlaps(MINUTIAE *minutiae,
if(to_remove[i]){ if(to_remove[i]){
/* Remove the minutia from the minutiae list. */ /* Remove the minutia from the minutiae list. */
if((ret = remove_minutia(i, minutiae))){ if((ret = remove_minutia(i, minutiae))){
free(to_remove); g_free(to_remove);
return(ret); return(ret);
} }
} }
} }
/* Deallocate flag list. */ /* Deallocate flag list. */
free(to_remove); g_free(to_remove);
/* Return normally. */ /* Return normally. */
return(0); 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 */ /* Allocate working memory for holding rotated y-coord of a */
/* minutia's contour. */ /* minutia's contour. */
rot_y = (int *)malloc(((lfsparms->side_half_contour<<1)+1) * sizeof(int)); rot_y = (int *)g_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);
}
/* Compute factor for converting integer directions to radians. */ /* Compute factor for converting integer directions to radians. */
pi_factor = M_PI / (double)lfsparms->num_directions; 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 system error occurred ... */
if(ret < 0){ if(ret < 0){
/* Deallocate working memory. */ /* Deallocate working memory. */
free(rot_y); g_free(rot_y);
/* Return error code. */ /* Return error code. */
return(ret); return(ret);
} }
@ -2077,7 +2072,7 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae,
/* Remove minutia from list. */ /* Remove minutia from list. */
if((ret = remove_minutia(i, minutiae))){ if((ret = remove_minutia(i, minutiae))){
/* Deallocate working memory. */ /* Deallocate working memory. */
free(rot_y); g_free(rot_y);
/* Return error code. */ /* Return error code. */
return(ret); return(ret);
} }
@ -2130,7 +2125,7 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae,
&minmax_alloc, &minmax_num, &minmax_alloc, &minmax_num,
rot_y, ncontour))){ rot_y, ncontour))){
/* If system error, then deallocate working memories. */ /* If system error, then deallocate working memories. */
free(rot_y); g_free(rot_y);
free_contour(contour_x, contour_y, contour_ex, contour_ey); free_contour(contour_x, contour_y, contour_ex, contour_ey);
/* Return error code. */ /* Return error code. */
return(ret); return(ret);
@ -2156,12 +2151,12 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae,
/* Remove minutia from list. */ /* Remove minutia from list. */
if((ret = remove_minutia(i, minutiae))){ if((ret = remove_minutia(i, minutiae))){
/* Deallocate working memory. */ /* Deallocate working memory. */
free(rot_y); g_free(rot_y);
free_contour(contour_x, contour_y, contour_ex, contour_ey); free_contour(contour_x, contour_y, contour_ex, contour_ey);
if(minmax_alloc > 0){ if(minmax_alloc > 0){
free(minmax_val); g_free(minmax_val);
free(minmax_type); g_free(minmax_type);
free(minmax_i); g_free(minmax_i);
} }
/* Return error code. */ /* Return error code. */
return(ret); return(ret);
@ -2202,12 +2197,12 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae,
/* Remove minutia from list. */ /* Remove minutia from list. */
if((ret = remove_minutia(i, minutiae))){ if((ret = remove_minutia(i, minutiae))){
/* Deallocate working memory. */ /* Deallocate working memory. */
free(rot_y); g_free(rot_y);
free_contour(contour_x, contour_y, contour_ex, contour_ey); free_contour(contour_x, contour_y, contour_ex, contour_ey);
if(minmax_alloc > 0){ if(minmax_alloc > 0){
free(minmax_val); g_free(minmax_val);
free(minmax_type); g_free(minmax_type);
free(minmax_i); g_free(minmax_i);
} }
/* Return error code. */ /* Return error code. */
return(ret); return(ret);
@ -2231,12 +2226,12 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae,
/* Remove minutia from list. */ /* Remove minutia from list. */
if((ret = remove_minutia(i, minutiae))){ if((ret = remove_minutia(i, minutiae))){
/* If system error, then deallocate working memories. */ /* If system error, then deallocate working memories. */
free(rot_y); g_free(rot_y);
free_contour(contour_x, contour_y, contour_ex, contour_ey); free_contour(contour_x, contour_y, contour_ex, contour_ey);
if(minmax_alloc > 0){ if(minmax_alloc > 0){
free(minmax_val); g_free(minmax_val);
free(minmax_type); g_free(minmax_type);
free(minmax_i); g_free(minmax_i);
} }
/* Return error code. */ /* Return error code. */
return(ret); return(ret);
@ -2248,15 +2243,15 @@ int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae,
/* Deallocate contour and min/max buffers. */ /* Deallocate contour and min/max buffers. */
free_contour(contour_x, contour_y, contour_ex, contour_ey); free_contour(contour_x, contour_y, contour_ex, contour_ey);
if(minmax_alloc > 0){ if(minmax_alloc > 0){
free(minmax_val); g_free(minmax_val);
free(minmax_type); g_free(minmax_type);
free(minmax_i); g_free(minmax_i);
} }
} /* End else contour extracted. */ } /* End else contour extracted. */
} /* End while not end of minutiae list. */ } /* End while not end of minutiae list. */
/* Deallocate working memory. */ /* Deallocate working memory. */
free(rot_y); g_free(rot_y);
/* Return normally. */ /* Return normally. */
return(0); return(0);

View file

@ -152,7 +152,7 @@ int count_minutia_ridges(const int first, MINUTIAE *minutiae,
if((ret = find_neighbors(&nbr_list, &nnbrs, lfsparms->max_nbrs, if((ret = find_neighbors(&nbr_list, &nnbrs, lfsparms->max_nbrs,
first, minutiae))){ first, minutiae))){
if (nbr_list != NULL) if (nbr_list != NULL)
free(nbr_list); g_free(nbr_list);
return(ret); return(ret);
} }
@ -167,18 +167,13 @@ int count_minutia_ridges(const int first, MINUTIAE *minutiae,
/* Sort neighbors on delta dirs. */ /* Sort neighbors on delta dirs. */
if((ret = sort_neighbors(nbr_list, nnbrs, first, minutiae))){ if((ret = sort_neighbors(nbr_list, nnbrs, first, minutiae))){
free(nbr_list); g_free(nbr_list);
return(ret); return(ret);
} }
/* Count ridges between first and neighbors. */ /* Count ridges between first and neighbors. */
/* List of ridge counts, one for each neighbor stored. */ /* List of ridge counts, one for each neighbor stored. */
nbr_nridges = (int *)malloc(nnbrs * sizeof(int)); nbr_nridges = (int *)g_malloc(nnbrs * sizeof(int));
if(nbr_nridges == (int *)NULL){
free(nbr_list);
fprintf(stderr, "ERROR : count_minutia_ridges : malloc : nbr_nridges\n");
return(-450);
}
/* Foreach neighbor found and sorted in list ... */ /* Foreach neighbor found and sorted in list ... */
for(i = 0; i < nnbrs; i++){ for(i = 0; i < nnbrs; i++){
@ -187,8 +182,8 @@ int count_minutia_ridges(const int first, MINUTIAE *minutiae,
/* If system error ... */ /* If system error ... */
if(ret < 0){ if(ret < 0){
/* Deallocate working memories. */ /* Deallocate working memories. */
free(nbr_list); g_free(nbr_list);
free(nbr_nridges); g_free(nbr_nridges);
/* Return error code. */ /* Return error code. */
return(ret); return(ret);
} }
@ -235,21 +230,11 @@ int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs,
double *nbr_sqr_dists, xdist, xdist2; double *nbr_sqr_dists, xdist, xdist2;
/* Allocate list of neighbor minutiae indices. */ /* Allocate list of neighbor minutiae indices. */
nbr_list = (int *)malloc(max_nbrs * sizeof(int)); nbr_list = (int *)g_malloc(max_nbrs * sizeof(int));
if(nbr_list == (int *)NULL){
fprintf(stderr, "ERROR : find_neighbors : malloc : nbr_list\n");
return(-460);
}
/* Allocate list of squared euclidean distances between neighbors */ /* Allocate list of squared euclidean distances between neighbors */
/* and current primary minutia point. */ /* and current primary minutia point. */
nbr_sqr_dists = (double *)malloc(max_nbrs * sizeof(double)); nbr_sqr_dists = (double *)g_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);
}
/* Initialize number of stored neighbors to 0. */ /* Initialize number of stored neighbors to 0. */
nnbrs = 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. */ /* Append or insert the new neighbor into the neighbor lists. */
if((ret = update_nbr_dists(nbr_list, nbr_sqr_dists, &nnbrs, max_nbrs, if((ret = update_nbr_dists(nbr_list, nbr_sqr_dists, &nnbrs, max_nbrs,
first, second, minutiae))){ first, second, minutiae))){
free(nbr_sqr_dists); g_free(nbr_sqr_dists);
free(nbr_list); g_free(nbr_list);
return(ret); return(ret);
} }
} }
@ -297,12 +282,12 @@ int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs,
} }
/* Deallocate working memory. */ /* Deallocate working memory. */
free(nbr_sqr_dists); g_free(nbr_sqr_dists);
/* If no neighbors found ... */ /* If no neighbors found ... */
if(nnbrs == 0){ if(nnbrs == 0){
/* Deallocate the neighbor list. */ /* Deallocate the neighbor list. */
free(nbr_list); g_free(nbr_list);
*onnbrs = 0; *onnbrs = 0;
} }
/* Otherwise, assign neighbors to output pointer. */ /* 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 */ /* List of angles of lines joining the current primary to each */
/* of the secondary neighbors. */ /* of the secondary neighbors. */
join_thetas = (double *)malloc(nnbrs * sizeof(double)); join_thetas = (double *)g_malloc(nnbrs * sizeof(double));
if(join_thetas == (double *)NULL){
fprintf(stderr, "ERROR : sort_neighbors : malloc : join_thetas\n");
return(-490);
}
for(i = 0; i < nnbrs; i++){ for(i = 0; i < nnbrs; i++){
/* Compute angle to line connecting the 2 points. */ /* 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); bubble_sort_double_inc_2(join_thetas, nbr_list, nnbrs);
/* Deallocate the list of angles. */ /* Deallocate the list of angles. */
free(join_thetas); g_free(join_thetas);
/* Return normally. */ /* Return normally. */
return(0); 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 */ /* It there are no points on the line trajectory, then no ridges */
/* to count (this should not happen, but just in case) ... */ /* to count (this should not happen, but just in case) ... */
if(num == 0){ if(num == 0){
free(xlist); g_free(xlist);
free(ylist); g_free(ylist);
return(0); 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 opposite pixel not found ... then no ridges to count */
if(!found){ if(!found){
free(xlist); g_free(xlist);
free(ylist); g_free(ylist);
return(0); 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 0-to-1 transition not found ... */
if(!find_transition(&i, 0, 1, xlist, ylist, num, bdata, iw, ih)){ if(!find_transition(&i, 0, 1, xlist, ylist, num, bdata, iw, ih)){
/* Then we are done looking for ridges. */ /* Then we are done looking for ridges. */
free(xlist); g_free(xlist);
free(ylist); g_free(ylist);
print2log("\n"); 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 1-to-0 transition not found ... */
if(!find_transition(&i, 1, 0, xlist, ylist, num, bdata, iw, ih)){ if(!find_transition(&i, 1, 0, xlist, ylist, num, bdata, iw, ih)){
/* Then we are done looking for ridges. */ /* Then we are done looking for ridges. */
free(xlist); g_free(xlist);
free(ylist); g_free(ylist);
print2log("\n"); print2log("\n");
@ -657,8 +638,8 @@ int ridge_count(const int first, const int second, MINUTIAE *minutiae,
/* If system error ... */ /* If system error ... */
if(ret < 0){ if(ret < 0){
free(xlist); g_free(xlist);
free(ylist); g_free(ylist);
/* Return the error code. */ /* Return the error code. */
return(ret); return(ret);
} }
@ -677,8 +658,8 @@ int ridge_count(const int first, const int second, MINUTIAE *minutiae,
} }
/* Deallocate working memories. */ /* Deallocate working memories. */
free(xlist); g_free(xlist);
free(ylist); g_free(ylist);
print2log("\n"); print2log("\n");

View file

@ -98,23 +98,11 @@ int alloc_shape(SHAPE **oshape, const int xmin, const int ymin,
alloc_pts = xmax - xmin + 1; alloc_pts = xmax - xmin + 1;
/* Allocate the shape structure. */ /* Allocate the shape structure. */
shape = (SHAPE *)malloc(sizeof(SHAPE)); shape = (SHAPE *)g_malloc(sizeof(SHAPE));
/* If there is an allocation error... */
if(shape == (SHAPE *)NULL){
fprintf(stderr, "ERROR : alloc_shape : malloc : shape\n");
return(-250);
}
/* Allocate the list of row pointers. We now this number will fit */ /* Allocate the list of row pointers. We now this number will fit */
/* the shape exactly. */ /* the shape exactly. */
shape->rows = (ROW **)malloc(alloc_rows * sizeof(ROW *)); shape->rows = (ROW **)g_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);
}
/* Initialize the shape structure's attributes. */ /* Initialize the shape structure's attributes. */
shape->ymin = ymin; 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++){ for(i = 0, y = ymin; i < alloc_rows; i++, y++){
/* Allocate a row structure and store it in its respective position */ /* Allocate a row structure and store it in its respective position */
/* in the shape structure's list of row pointers. */ /* in the shape structure's list of row pointers. */
shape->rows[i] = (ROW *)malloc(sizeof(ROW)); shape->rows[i] = (ROW *)g_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);
}
/* Allocate the current rows list of x-coords. */ /* Allocate the current rows list of x-coords. */
shape->rows[i]->xs = (int *)malloc(alloc_pts * sizeof(int)); shape->rows[i]->xs = (int *)g_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);
}
/* Initialize the current row structure's attributes. */ /* Initialize the current row structure's attributes. */
shape->rows[i]->y = y; shape->rows[i]->y = y;
@ -188,15 +150,15 @@ void free_shape(SHAPE *shape)
/* Foreach allocated row in the shape ... */ /* Foreach allocated row in the shape ... */
for(i = 0; i < shape->alloc; i++){ for(i = 0; i < shape->alloc; i++){
/* Deallocate the current row's list of x-coords. */ /* 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. */ /* Deallocate the current row structure. */
free(shape->rows[i]); g_free(shape->rows[i]);
} }
/* Deallocate the list of row pointers. */ /* Deallocate the list of row pointers. */
free(shape->rows); g_free(shape->rows);
/* Deallocate the shape structure. */ /* 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){ if(row->npts >= row->alloc){
/* This should never happen becuase we have allocated */ /* This should never happen becuase we have allocated */
/* based on shape bounding limits. */ /* based on shape bounding limits. */
free(shape); g_free(shape);
fprintf(stderr, fprintf(stderr,
"ERROR : shape_from_contour : row overflow\n"); "ERROR : shape_from_contour : row overflow\n");
return(-260); return(-260);

View file

@ -89,11 +89,7 @@ int sort_indices_int_inc(int **optr, int *ranks, const int num)
int i; int i;
/* Allocate list of sequential indices. */ /* Allocate list of sequential indices. */
order = (int *)malloc(num * sizeof(int)); order = (int *)g_malloc(num * sizeof(int));
if(order == (int *)NULL){
fprintf(stderr, "ERROR : sort_indices_int_inc : malloc : order\n");
return(-390);
}
/* Initialize list of sequential indices. */ /* Initialize list of sequential indices. */
for(i = 0; i < num; i++) for(i = 0; i < num; i++)
order[i] = i; order[i] = i;

View file

@ -178,24 +178,9 @@ int minmaxs(int **ominmax_val, int **ominmax_type, int **ominmax_i,
/* min or max. */ /* min or max. */
minmax_alloc = num - 2; minmax_alloc = num - 2;
/* Allocate the buffers. */ /* Allocate the buffers. */
minmax_val = (int *)malloc(minmax_alloc * sizeof(int)); minmax_val = (int *)g_malloc(minmax_alloc * sizeof(int));
if(minmax_val == (int *)NULL){ minmax_type = (int *)g_malloc(minmax_alloc * sizeof(int));
fprintf(stderr, "ERROR : minmaxs : malloc : minmax_val\n"); minmax_i = (int *)g_malloc(minmax_alloc * sizeof(int));
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);
}
/* Initialize number of min/max to 0. */ /* Initialize number of min/max to 0. */
minmax_num = 0; minmax_num = 0;