Skip to content

Commit ce34716

Browse files
committed
close style file on error
Fixes osm2pgsql-dev#601.
1 parent 76ebd78 commit ce34716

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

taginfo.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ int read_style_file( const std::string &filename, export_list *exlist )
158158
if( fields < 3 )
159159
{
160160
fprintf( stderr, "Error reading style file line %d (fields=%d)\n", lineno, fields );
161+
fclose(in);
161162
util::exit_nicely();
162163
}
163164

@@ -176,6 +177,7 @@ int read_style_file( const std::string &filename, export_list *exlist )
176177
((temp.name.find('?') != std::string::npos) ||
177178
(temp.name.find('*') != std::string::npos))) {
178179
fprintf( stderr, "wildcard '%s' in non-delete style entry\n",temp.name.c_str());
180+
fclose(in);
179181
util::exit_nicely();
180182
}
181183

@@ -203,6 +205,7 @@ int read_style_file( const std::string &filename, export_list *exlist )
203205
//do we really want to completely quit on an unusable line?
204206
if( !kept )
205207
{
208+
fclose(in);
206209
throw std::runtime_error((boost::format("Weird style line %1%:%2%")
207210
% filename % lineno).str());
208211
}
@@ -211,13 +214,15 @@ int read_style_file( const std::string &filename, export_list *exlist )
211214

212215

213216
if (ferror(in)) {
217+
int err = errno;
218+
fclose(in);
214219
throw std::runtime_error((boost::format("%1%: %2%")
215-
% filename % strerror(errno)).str());
220+
% filename % strerror(err)).str());
216221
}
222+
fclose(in);
217223
if (num_read == 0) {
218224
throw std::runtime_error("Unable to parse any valid columns from "
219225
"the style file. Aborting.");
220226
}
221-
fclose(in);
222227
return enable_way_area;
223228
}

0 commit comments

Comments
 (0)