Skip to content

Commit 633b026

Browse files
authored
r.li: only close files that are opened (#5605)
1 parent 4807e82 commit 633b026

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

raster/r.li/r.li.daemon/worker.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,20 @@ char *mask_preprocessing(char *mask, char *raster, struct area_entry *ad)
217217
int mask_fd, old_fd, *buf, i, j;
218218
CELL *old;
219219

220-
buf = G_malloc(ad->cl * sizeof(int));
221-
222220
G_debug(3, "daemon mask preproc: raster=[%s] mask=[%s] rl=%d cl=%d",
223221
raster, mask, ad->rl, ad->cl);
224222

225223
tmp_file = G_tempfile();
226-
mask_fd = open(tmp_file, O_RDWR | O_CREAT, 0755);
224+
if ((mask_fd = open(tmp_file, O_RDWR | O_CREAT, 0755) < 0)) {
225+
G_free(tmp_file);
226+
return NULL;
227+
}
228+
227229
old_fd = Rast_open_old(mask, "");
228230
old = Rast_allocate_c_buf();
229231

232+
buf = G_malloc(ad->cl * sizeof(int));
233+
230234
/* write out sample area size: ad->rl rows and ad->cl columns */
231235

232236
for (i = 0; i < ad->rl; i++) {

raster/r.li/r.li.edgedensity/edgedensity.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ int calculateD(int fd, struct area_entry *ad, char **par, double *result)
354354

355355
buf_null = Rast_allocate_d_buf();
356356
if (buf_null == NULL) {
357-
close(mask_fd);
357+
if (masked)
358+
close(mask_fd);
358359
G_fatal_error("malloc buf_null failed");
359360
}
360361

@@ -553,7 +554,8 @@ int calculateF(int fd, struct area_entry *ad, char **par, double *result)
553554

554555
buf_null = Rast_allocate_f_buf();
555556
if (buf_null == NULL) {
556-
close(mask_fd);
557+
if (masked)
558+
close(mask_fd);
557559
G_fatal_error("malloc buf_null failed");
558560
}
559561

0 commit comments

Comments
 (0)