projects
/
mymail.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
319a695
)
Fixed two memory leaks.
author
Francois Fleuret
<francois@fleuret.org>
Mon, 28 Jan 2013 13:09:13 +0000
(14:09 +0100)
committer
Francois Fleuret
<francois@fleuret.org>
Mon, 28 Jan 2013 13:09:13 +0000
(14:09 +0100)
mymail.c
patch
|
blob
|
history
diff --git
a/mymail.c
b/mymail.c
index
6388365
..
99a76d8
100644
(file)
--- a/
mymail.c
+++ b/
mymail.c
@@
-89,7
+89,7
@@
void search_in_db(const char *search_name, const char *search_regexp_string,
FILE *db_file) {
char raw_line[BUFFER_SIZE];
char current_mail_filename[BUFFER_SIZE];
FILE *db_file) {
char raw_line[BUFFER_SIZE];
char current_mail_filename[BUFFER_SIZE];
- unsigned int current_position_in_mail;
+ unsigned
long
int current_position_in_mail;
char *name, *value;
regex_t regexp;
int already_written;
char *name, *value;
regex_t regexp;
int already_written;
@@
-111,20
+111,18
@@
void search_in_db(const char *search_name, const char *search_regexp_string,
name = raw_line;
value = segment_next_field(raw_line);
name = raw_line;
value = segment_next_field(raw_line);
- /* printf("LINE [%s] %s", name, value); */
-
if(strcmp("mail", name) == 0) {
char *position_in_file_string = value;
char *mail_filename = segment_next_field(value);
if(strcmp("mail", name) == 0) {
char *position_in_file_string = value;
char *mail_filename = segment_next_field(value);
- current_position_in_mail = ato
i
(position_in_file_string);
+ current_position_in_mail = ato
l
(position_in_file_string);
strcpy(current_mail_filename, mail_filename);
remove_eof(current_mail_filename);
strcpy(current_mail_filename, mail_filename);
remove_eof(current_mail_filename);
- /* printf("READING [%s]\n", current_mail_filename); */
already_written = 0;
already_written = 0;
- } else if(!already_written) {
- if(strcmp(search_name, name) == 0 && regexec(®exp, value, 0, 0, 0) == 0) {
+ }
+
+ else if(!already_written) {
+ if(strcmp(search_name, name) == 0 && regexec(®exp, value, 0, 0, 0) == 0) {
FILE *mail_file;
FILE *mail_file;
- /* printf("%s:%u\n", current_mail_filename, current_position_in_mail); */
mail_file = fopen(current_mail_filename, "r");
if(!mail_file) {
fprintf(stderr, "mymail: Can not open `%s'.\n", current_mail_filename);
mail_file = fopen(current_mail_filename, "r");
if(!mail_file) {
fprintf(stderr, "mymail: Can not open `%s'.\n", current_mail_filename);
@@
-143,6
+141,8
@@
void search_in_db(const char *search_name, const char *search_regexp_string,
}
}
}
}
}
}
+
+ regfree(®exp);
}
}
@@
-154,7
+154,7
@@
void read_file(const char *input_filename,
char raw_line[BUFFER_SIZE];
FILE *file;
int in_header, new_header;
char raw_line[BUFFER_SIZE];
FILE *file;
int in_header, new_header;
- unsigned int position_in_file;
+ unsigned
long
int position_in_file;
file = fopen(input_filename, "r");
file = fopen(input_filename, "r");
@@
-172,7
+172,7
@@
void read_file(const char *input_filename,
if(strncmp(raw_line, "From ", 5) == 0) {
if(in_header) {
fprintf(stderr,
if(strncmp(raw_line, "From ", 5) == 0) {
if(in_header) {
fprintf(stderr,
- "Got a 'From ' in the header in %s:%u.\n",
+ "Got a 'From ' in the header in %s:%
l
u.\n",
input_filename, position_in_file);
fprintf(stderr, "%s", raw_line);
exit(EXIT_FAILURE);
input_filename, position_in_file);
fprintf(stderr, "%s", raw_line);
exit(EXIT_FAILURE);
@@
-193,7
+193,7
@@
void read_file(const char *input_filename,
int f;
regmatch_t matches;
if(new_header) {
int f;
regmatch_t matches;
if(new_header) {
- fprintf(db_file, "mail %u %s\n", position_in_file, input_filename);
+ fprintf(db_file, "mail %
l
u %s\n", position_in_file, input_filename);
new_header = 0;
}
for(f = 0; f < nb_fields_to_parse; f++) {
new_header = 0;
}
for(f = 0; f < nb_fields_to_parse; f++) {
@@
-213,8
+213,8
@@
void read_file(const char *input_filename,
int ignore_entry(const char *name) {
return
int ignore_entry(const char *name) {
return
- strcmp(name, ".") == 0 ||
- strcmp(name, "..") == 0 ||
+ /* strcmp(name, ".") == 0 || */
+ /* strcmp(name, "..") == 0 || */
(name[0] == '.' && name[1] != '/');
}
(name[0] == '.' && name[1] != '/');
}
@@
-232,12
+232,11
@@
void process_entry(const char *dir_name,
dir_name,
strerror(errno));
exit(EXIT_FAILURE);
dir_name,
strerror(errno));
exit(EXIT_FAILURE);
- } else {
}
}
- if(S_ISLNK(sb.st_mode)) {
- return;
- }
+ /* if(S_ISLNK(sb.st_mode)) { */
+ /* return; */
+ /* } */
dir = opendir(dir_name);
dir = opendir(dir_name);
@@
-251,10
+250,9
@@
void process_entry(const char *dir_name,
}
closedir(dir);
} else {
}
closedir(dir);
} else {
- if(S_ISREG(sb.st_mode)) {
- /* printf("Processing regular file '%s'.\n", dir_name); */
+ /* if(S_ISREG(sb.st_mode)) { */
read_file(dir_name, nb_fields_to_parse, fields_to_parse, db_file);
read_file(dir_name, nb_fields_to_parse, fields_to_parse, db_file);
- }
+ /* } */
}
}
}
}
@@
-416,5
+414,7
@@
int main(int argc, char **argv) {
}
}
}
}
+ free(db_filename);
+
exit(EXIT_SUCCESS);
}
exit(EXIT_SUCCESS);
}