some error handling and close handle before deleting the temporary file

This commit is contained in:
Sebastian Ramacher 2010-10-04 10:08:21 +02:00
parent 9fa858b2ff
commit 3210e5be28

View file

@ -1419,9 +1419,21 @@ open_stdin(gchar* password)
}
// 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];
ssize_t count = 0;
int stdinfno = fileno(stdin);
while ((count = read(stdinfno, buffer, BUFSIZ)) > 0)
{
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);
notify(ERROR, message);
g_free(message);
close(handle);
g_unlink(file);
g_free(file);
close(handle);
return FALSE;
}
}
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);
g_free(message);
close(handle);
g_unlink(file);
g_free(file);
close(handle);
return FALSE;
}