Browse Source

- fixed memleaks

development
Andreas Romeyke 2 years ago
parent
commit
b51e61a45f
8 changed files with 62 additions and 34 deletions
  1. +5
    -5
      src/headers/check.h
  2. +2
    -2
      src/headers/config_parser.h
  3. +4
    -6
      src/helper/check_helper.c
  4. +9
    -3
      src/helper/check_tiffparse.c
  5. +6
    -2
      src/ifdrules/check_all_geotiff_tags.c
  6. +3
    -1
      src/ifdrules/check_all_offsets_greater_zero.c
  7. +21
    -11
      src/parser/config_parser.c
  8. +12
    -4
      src/tagrules/check_tag_has_value_quiet.c

+ 5
- 5
src/headers/check.h View File

@ -243,11 +243,11 @@ ret_t tif_no_tag(tag_t tag);
ret_t _empty_result();
*/
const char * float2str(float v);
const char* tag2str(tag_t tag);
const char* int2str(int v);
const char* frac2str(int d, int n);
const char* range2str(int d, int n);
char* float2str(float v);
char* tag2str(tag_t tag);
char* int2str(int v);
char* frac2str(int d, int n);
char* range2str(int d, int n);
off_t ct_seek(ctiff_t * ctif, off_t pos, int whence);
ssize_t ct_read(ctiff_t * ctif, void *buf, size_t count);
ret_t check_tag_has_some_of_these_values( ctiff_t * ctif, tag_t tag, int count, const unsigned int * values);


+ 2
- 2
src/headers/config_parser.h View File

@ -68,7 +68,7 @@ typedef struct internal_entry_s {
tag_t tag;
function_t function;
values_t val_stack[INTERNALSTACKDEPTH];
const char * regex_stack[INTERNALSTACKDEPTH];
char * regex_stack[INTERNALSTACKDEPTH];
unsigned int i_stack[INTERNALSTACKDEPTH];
int i_stackp;
int val_stackp;
@ -91,7 +91,7 @@ typedef struct parser_state_s {
tag_t tag;
tag_t tagref;
values_t val_stack[MAXSTACKDEPTH];
const char * regex_stack[MAXSTACKDEPTH];
char * regex_stack[MAXSTACKDEPTH];
requirements_t req;
unsigned int i_stack[MAXSTACKDEPTH];
int i_stackp;


+ 4
- 6
src/helper/check_helper.c View File

@ -43,19 +43,19 @@ char * secstrcat (char * dest, const char * src, const size_t * maxsize_p) {
return dest;
}
const char * float2str(float v) {
char * float2str(float v) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "%f", v);
return strdup(array);
}
const char* int2str(int v) {
char* int2str(int v) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "%i", v);
return strdup(array);
}
const char* frac2str(int d, int n) {
char* frac2str(int d, int n) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "%i/%i", d, n);
return strdup(array);
@ -85,12 +85,10 @@ long long fsize(int fd) {
ret_t set_value_found_ret (ret_t * rp, const char * msg) {
assert( NULL != rp);
assert( NULL != msg);
rp->value_found=malloc(sizeof(char) * VALUESTRLEN);
rp->value_found=calloc(VALUESTRLEN, sizeof(char));
if (NULL == rp->value_found) {
rp->returncode=could_not_allocate_memory;
} else {
memset(rp->value_found, '\0', VALUESTRLEN);
// printf("DEBUG='%s'\n", msg);
strncpy(rp->value_found, msg, VALUESTRLEN-1);
// printf("DEBUG2='%s'\n", rp->value_found);
}


+ 9
- 3
src/helper/check_tiffparse.c View File

@ -161,7 +161,9 @@ ret_t check_tag_has_fvalue(ctiff_t * ctif, tag_t tag, float value) {
ret.returncode=is_valid;
return ret;
} else {
ret = set_value_found_ret(&ret, float2str(val)) ;
char * msg = float2str(val);
ret = set_value_found_ret(&ret, msg ) ;
free ( msg );
ret.returncode = tagerror_value_differs;
}
}
@ -182,7 +184,9 @@ ret_t check_tag_has_u16value(ctiff_t * ctif, tag_t tag, uint16 value) {
ret.returncode=is_valid;
return ret;
} else {
ret = set_value_found_ret(&ret, int2str(val));
char * msg = int2str(val);
ret = set_value_found_ret(&ret, msg );
free ( msg );
ret.returncode = tagerror_value_differs;
return ret;
}
@ -207,7 +211,9 @@ ret_t check_tag_has_u32value(ctiff_t * ctif, tag_t tag, uint32 value) {
ret.returncode=is_valid;
return ret;
} else {
ret = set_value_found_ret(&ret, int2str(val));
char * msg = int2str(val);
ret = set_value_found_ret(&ret, msg );
free ( msg );
ret.returncode = tagerror_value_differs;
return ret;
}


+ 6
- 2
src/ifdrules/check_all_geotiff_tags.c View File

@ -64,12 +64,16 @@ ret_t check_all_geotiff_tags(ctiff_t * ctif) {
ifd_entry_t ifd_entry = TIFFGetRawIFDEntry(ctif, 34735);
/* only one ifd? */
if (ifd_entry.count < 4) {
ret = set_value_found_ret(&ret, int2str(ifd_entry.count));
char * msg = int2str(ifd_entry.count);
ret = set_value_found_ret(&ret, msg );
free( msg );
ret.returncode = tagerror_expected_count_less_than_four;
return ret;
}
if (ifd_entry.count % 4 != 0) {
ret = set_value_found_ret(&ret, int2str(ifd_entry.count));
char * msg = int2str(ifd_entry.count);
ret = set_value_found_ret(&ret, msg );
free( msg );
ret.returncode = tagerror_expected_count_not_a_multiple_of_four;
return ret;
}


+ 3
- 1
src/ifdrules/check_all_offsets_greater_zero.c View File

@ -25,7 +25,9 @@ ret_t check_all_offsets_are_greater_zero(ctiff_t * ctif) {
if (ifd_entry.value_or_offset==is_offset) offset = ifd_entry.data32offset;
else if (tag == TIFFTAG_EXIFIFD) {
if (ifd_entry.count > 1) {
ret = set_value_found_ret(&ret, int2str(ifd_entry.count));
char * msg = int2str(ifd_entry.count);
ret = set_value_found_ret(&ret, msg);
free(msg);
ret.returncode = tagerror_expected_count_isgreaterone;
return ret;
}


+ 21
- 11
src/parser/config_parser.c View File

@ -124,8 +124,8 @@ void v_push ( values_t v) { PUSH(&parser_state, val, v);}
values_t v_pop () { values_t v; POP(&parser_state, val, v); return v; }
void r_printstack () { PRINT(&parser_state, "%s", regex); }
void r_push (const char * r) { PUSH(&parser_state, regex, r); }
const char * r_pop () { const char * v; POP(&parser_state, regex, v); return v; }
void r_push (char * r) { PUSH(&parser_state, regex, r); }
char * r_pop () { char * v; POP(&parser_state, regex, v); return v; }
void exe_push (internal_entry_t i) { PUSH(&parser_state, exe, i);}
internal_entry_t exe_pop () { internal_entry_t e; POP(&parser_state, exe, e); return e; }
@ -217,6 +217,14 @@ void reduce_results() {
if (l_full_result.returncode == parser_logical_combine_close) {
if (one_result_is_ok == true) {
full_result.returncode = is_valid;
/* free all combined values */
/* iterate and free all "ignored" entries */
for (int k=i+1; k<j; k++) {
if (NULL != parser_state.result_stack[k].found_value) {
free( parser_state.result_stack[k].found_value);
parser_state.result_stack[k].found_value = NULL;
}
}
i=j;
#ifdef DEBUG
printf("\tend combine i=%i j=%i\n", i, j);
@ -237,11 +245,12 @@ void reduce_results() {
/* push to tmp */
tmp[tmpc++]=full_result;
}
} /* end for loop */
/* copy back */
for (int i = 0; i <= tmpc; i++) {
parser_state.result_stack[i]= tmp[i];
}
free(tmp);
tmp=NULL;
/* copy size */
@ -271,8 +280,8 @@ internal_entry_t * exe_regex_push (internal_entry_t * ep, const char * s) {
#endif
return ep;
}
const char * exe_regex_pop(internal_entry_t * ep) {
const char * s;
char * exe_regex_pop(internal_entry_t * ep) {
char * s;
POP( ep, regex, s);
#ifdef EXE_DEBUG
printf("-------------------\n");
@ -285,11 +294,10 @@ const char * exe_regex_pop(internal_entry_t * ep) {
char * __ch_malloc(char * msg) {
assert( msg == NULL);
msg = malloc(sizeof(char) * VALUESTRLEN );
msg = calloc(VALUESTRLEN, sizeof(char));
if (NULL == msg) {
fprintf(stderr, "Could not allocate memory, code=%s, line=%i\n", __FILE__, __LINE__); exit(could_not_allocate_memory);
}
memset(msg, '\0', VALUESTRLEN);
return msg;
}
@ -369,10 +377,11 @@ ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep)
case fc_has_only_one_ifd: { ret = check_has_only_one_ifd(ctif); break;}
case fc_tagorder: { ret = check_tagorder(ctif); break;}
case fc_tag_has_valid_asciivalue: { ret = check_tag_has_valid_asciivalue(ctif, exe.tag); break;}
case fc_tag_has_value_matching_regex: { const char * regex_string = exe_regex_pop( &exe);
case fc_tag_has_value_matching_regex: { char * regex_string = exe_regex_pop( &exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, "regex=%s", regex_string);
ret = check_tag_has_value_matching_regex(ctif, exe.tag, regex_string);
free( regex_string );
break;
}
case fc_all_offsets_are_word_aligned: { ret = check_all_offsets_are_word_aligned(ctif); break;}
@ -381,7 +390,7 @@ ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep)
case fc_internal_logic_combine_open: { ret.returncode = parser_logical_combine_open ; break; }
case fc_internal_logic_combine_close: { ret.returncode = parser_logical_combine_close ; break; }
case fc_all_offsets_are_not_zero: { ret = check_all_offsets_are_greater_zero(ctif); break;}
case fc_all_geotiff_tags_have_same_count_of_values: {
case fc_all_geotiff_tags_have_same_count_of_values: {
ret = check_all_geotiff_tags(ctif); break;
}
@ -512,7 +521,7 @@ void execute_plan (ctiff_t * ctif) {
*/
if (ret.returncode != is_valid) {
full.found_value = ret.value_found;
}
} else { free( ret.value_found ); ret.value_found=NULL; }
result_push( full );
precondition_result=is_valid;
precondition_function = exe.function;
@ -577,6 +586,7 @@ void execute_plan (ctiff_t * ctif) {
full.found_value=NULL;
result_push( full );
}
free( res.value_found );
}
}
#endif /* NOTAGCHECK */
@ -670,7 +680,7 @@ void set_optdepends() {
/* helper function for parser */
void regex_push( const char * regex_string) {
void regex_push( char * regex_string) {
pcre *re;
int erroffset;
const char * errorcode;


+ 12
- 4
src/tagrules/check_tag_has_value_quiet.c View File

@ -25,14 +25,18 @@ ret_t check_tag_has_value_quiet(ctiff_t * ctif, tag_t tag, unsigned int expected
ifd_entry_t ifd_entry = TIFFGetRawIFDEntry(ctif, tag);
if (ifd_entry.count > 1) {
ret = set_value_found_ret(&ret, int2str(ifd_entry.count));
char * msg = int2str(ifd_entry.count);
ret = set_value_found_ret(&ret, msg );
free( msg );
ret.returncode = tagerror_expected_count_isgreaterone;
return ret;
}
switch (ifd_entry.datatype) {
case TIFF_LONG: {
if (expected_value != ifd_entry.data32) {
ret = set_value_found_ret(&ret, int2str(ifd_entry.data32));
char * msg = int2str(ifd_entry.data32);
ret = set_value_found_ret(&ret, msg);
free( msg );
ret.returncode = tagerror_value_differs;
return ret;
}
@ -40,7 +44,9 @@ ret_t check_tag_has_value_quiet(ctiff_t * ctif, tag_t tag, unsigned int expected
}
case TIFF_SHORT: {
if (expected_value != ifd_entry.data16[0]) {
ret = set_value_found_ret(&ret, int2str(ifd_entry.data16[0]));
char * msg = int2str(ifd_entry.data16[0]);
ret = set_value_found_ret(&ret, msg );
free( msg );
ret.returncode = tagerror_value_differs;
return ret;
}
@ -54,7 +60,9 @@ ret_t check_tag_has_value_quiet(ctiff_t * ctif, tag_t tag, unsigned int expected
ret.returncode = tagerror_denominator_is_zero_in_fract;
return ret;
} else if (expected_value - (ifd_entry.data16[0] / ifd_entry.data16[1]) > 1) {
ret = set_value_found_ret(&ret, frac2str( ifd_entry.data16[0], ifd_entry.data16[1]));
char * msg = frac2str( ifd_entry.data16[0], ifd_entry.data16[1]);
ret = set_value_found_ret(&ret, msg );
free ( msg );
ret.returncode = tagerror_value_differs;
return ret;
}


Loading…
Cancel
Save