mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-01 06:46:01 +01:00
some error handling and close handle before deleting the temporary file
This commit is contained in:
parent
9fa858b2ff
commit
3210e5be28
1 changed files with 16 additions and 4 deletions
20
zathura.c
20
zathura.c
|
@ -1419,9 +1419,21 @@ open_stdin(gchar* password)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read from stdin and dump to temporary file
|
// read from stdin and dump to temporary file
|
||||||
|
int stdinfno = fileno(stdin);
|
||||||
|
if (stdinfno == -1)
|
||||||
|
{
|
||||||
|
gchar* message = g_strdup_printf("Can not read from stdin.");
|
||||||
|
notify(ERROR, message);
|
||||||
|
g_free(message);
|
||||||
|
close(handle);
|
||||||
|
g_unlink(file);
|
||||||
|
g_free(file);
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
ssize_t count = 0;
|
ssize_t count = 0;
|
||||||
int stdinfno = fileno(stdin);
|
|
||||||
while ((count = read(stdinfno, buffer, BUFSIZ)) > 0)
|
while ((count = read(stdinfno, buffer, BUFSIZ)) > 0)
|
||||||
{
|
{
|
||||||
if (write(handle, buffer, count) != count)
|
if (write(handle, buffer, count) != count)
|
||||||
|
@ -1429,21 +1441,21 @@ open_stdin(gchar* password)
|
||||||
gchar* message = g_strdup_printf("Can not write to temporary file: %s", file);
|
gchar* message = g_strdup_printf("Can not write to temporary file: %s", file);
|
||||||
notify(ERROR, message);
|
notify(ERROR, message);
|
||||||
g_free(message);
|
g_free(message);
|
||||||
|
close(handle);
|
||||||
g_unlink(file);
|
g_unlink(file);
|
||||||
g_free(file);
|
g_free(file);
|
||||||
close(handle);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count != 0)
|
if (count != 0)
|
||||||
{
|
{
|
||||||
gchar* message = g_strdup_printf("Can not read from stdin");
|
gchar* message = g_strdup_printf("Can not read from stdin.");
|
||||||
notify(ERROR, message);
|
notify(ERROR, message);
|
||||||
g_free(message);
|
g_free(message);
|
||||||
|
close(handle);
|
||||||
g_unlink(file);
|
g_unlink(file);
|
||||||
g_free(file);
|
g_free(file);
|
||||||
close(handle);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue