Skip to content

Commit 36237f3

Browse files
committed
Cleanup previous PR
1 parent 5b4ccff commit 36237f3

1 file changed

Lines changed: 6 additions & 30 deletions

File tree

kitty/dnd.c

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,14 +1482,14 @@ parse_uri_list(Window *w, int fd, size_t *num_uris_out) {
14821482
off_t file_size = lseek(fd, 0, SEEK_END);
14831483
if (file_size < 0) { cancel_drag(w, EIO); return NULL; }
14841484
if (lseek(fd, 0, SEEK_SET) < 0) { cancel_drag(w, EIO); return NULL; }
1485-
char *buf = malloc((size_t)file_size + 1);
1485+
RAII_ALLOC(char, buf, malloc((size_t)file_size + 1));
14861486
if (!buf) { cancel_drag(w, ENOMEM); return NULL; }
14871487
size_t total = 0;
14881488
while (total < (size_t)file_size) {
14891489
ssize_t n = read(fd, buf + total, (size_t)file_size - total);
14901490
if (n < 0) {
14911491
if (errno == EINTR) continue;
1492-
free(buf); cancel_drag(w, EIO); return NULL;
1492+
cancel_drag(w, EIO); return NULL;
14931493
}
14941494
if (n == 0) break;
14951495
total += (size_t)n;
@@ -1513,8 +1513,8 @@ parse_uri_list(Window *w, int fd, size_t *num_uris_out) {
15131513
while (*p == '\r' || *p == '\n') p++;
15141514
}
15151515

1516-
const char **result = malloc((count + 1) * sizeof(const char*));
1517-
if (!result) { free(buf); cancel_drag(w, ENOMEM); return NULL; }
1516+
const char **result = calloc((count + 1), sizeof(const char*));
1517+
if (!result) { cancel_drag(w, ENOMEM); return NULL; }
15181518

15191519
// Second pass: fill in decoded URI strings
15201520
size_t idx = 0;
@@ -1526,32 +1526,10 @@ parse_uri_list(Window *w, int fd, size_t *num_uris_out) {
15261526
while (end > p && (end[-1] == ' ' || end[-1] == '\t')) end--;
15271527
*end = '\0';
15281528
if (*p && *p != '#') {
1529-
char *decoded = NULL;
1530-
if (strncmp(p, "file://", 7) == 0) {
1531-
const char *rest = p + 7;
1532-
const char *slash = strchr(rest, '/');
1533-
if (slash) {
1534-
size_t host_len = (size_t)(slash - rest);
1535-
if (host_len == 0 || (host_len == 9 && strncasecmp(rest, "localhost", 9) == 0)) {
1536-
decoded = strdup(slash);
1537-
if (decoded) {
1538-
char *qf = decoded + strcspn(decoded, "?#");
1539-
*qf = '\0';
1540-
url_decode_inplace(decoded);
1541-
}
1542-
} else {
1543-
decoded = strdup(p);
1544-
}
1545-
} else {
1546-
decoded = strdup(p);
1547-
}
1548-
} else {
1549-
decoded = strdup(p);
1550-
}
1529+
char *decoded = strdup(p);
15511530
if (!decoded) {
15521531
for (size_t k = 0; k < idx; k++) free((char*)result[k]);
1553-
free(result); free(buf);
1554-
cancel_drag(w, ENOMEM); return NULL;
1532+
free(result); cancel_drag(w, ENOMEM); return NULL;
15551533
}
15561534
result[idx++] = decoded;
15571535
}
@@ -1560,8 +1538,6 @@ parse_uri_list(Window *w, int fd, size_t *num_uris_out) {
15601538
p = eol + 1;
15611539
while (*p == '\r' || *p == '\n') p++;
15621540
}
1563-
result[idx] = NULL;
1564-
free(buf);
15651541
*num_uris_out = idx;
15661542
return result;
15671543
}

0 commit comments

Comments
 (0)