projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix memory leaks reported by Address Sanitizer.
[pspp]
/
src
/
data
/
make-file.c
diff --git
a/src/data/make-file.c
b/src/data/make-file.c
index b67ed307019b87133ec343ab1f7893f782f3f360..a1a541a5d0fb81c6c8938050ce6c3339f1ab31d5 100644
(file)
--- a/
src/data/make-file.c
+++ b/
src/data/make-file.c
@@
-19,7
+19,6
@@
#include "data/make-file.h"
#include "libpspp/i18n.h"
#include "data/make-file.h"
#include "libpspp/i18n.h"
-#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@
-45,7
+44,6
@@
#if defined _WIN32 || defined __WIN32__
#define WIN32_LEAN_AND_MEAN /* avoid including junk */
#if defined _WIN32 || defined __WIN32__
#define WIN32_LEAN_AND_MEAN /* avoid including junk */
-#define UNICODE 1
#include <windows.h>
#define TS_stat _stat
#define Tunlink _wunlink
#include <windows.h>
#define TS_stat _stat
#define Tunlink _wunlink
@@
-149,7
+147,7
@@
Trename (TCHAR const *src, TCHAR const *dst)
return -1;
}
return -1;
}
-static TCHAR *
+TCHAR *
convert_to_filename_encoding (const char *s, size_t len, const char *current_encoding)
{
const char *enc = current_encoding;
convert_to_filename_encoding (const char *s, size_t len, const char *current_encoding)
{
const char *enc = current_encoding;
@@
-161,17
+159,16
@@
convert_to_filename_encoding (const char *s, size_t len, const char *current_enc
#else
#else
-typedef char TCHAR;
#define TS_stat stat
#define Trename rename
#define Tunlink unlink
#define Topen open
#define Tstat stat
#define TS_stat stat
#define Trename rename
#define Tunlink unlink
#define Topen open
#define Tstat stat
-static TCHAR *
+TCHAR *
convert_to_filename_encoding (const char *s, size_t len UNUSED, const char *current_encoding UNUSED)
{
convert_to_filename_encoding (const char *s, size_t len UNUSED, const char *current_encoding UNUSED)
{
- /* Non-windows systems don't care about the encoding.
+ /* Non-windows systems don't care about the encoding.
The string is copied here, to be consistent with the w32 case. */
return xstrdup (s);
}
The string is copied here, to be consistent with the w32 case. */
return xstrdup (s);
}
@@
-188,11
+185,11
@@
struct replace_file
char *tmp_name_verbatim;
const char *file_name_verbatim;
};
char *tmp_name_verbatim;
const char *file_name_verbatim;
};
-
+
static struct ll_list all_files = LL_INITIALIZER (all_files);
static void free_replace_file (struct replace_file *);
static struct ll_list all_files = LL_INITIALIZER (all_files);
static void free_replace_file (struct replace_file *);
-static void unlink_replace_files (
void
);
+static void unlink_replace_files (
int sig
);
struct replace_file *
replace_file_start (const struct file_handle *fh, const char *mode,
struct replace_file *
replace_file_start (const struct file_handle *fh, const char *mode,
@@
-216,7
+213,7
@@
replace_file_start (const struct file_handle *fh, const char *mode,
fd = Topen (Tfile_name, O_WRONLY);
if (fd < 0)
{
fd = Topen (Tfile_name, O_WRONLY);
if (fd < 0)
{
- saved_errno = errno;
+ saved_errno = errno;
msg (ME, _("Opening %s for writing: %s."),
file_name, strerror (saved_errno));
free (Tfile_name);
msg (ME, _("Opening %s for writing: %s."),
file_name, strerror (saved_errno));
free (Tfile_name);
@@
-227,7
+224,7
@@
replace_file_start (const struct file_handle *fh, const char *mode,
*fp = fdopen (fd, mode);
if (*fp == NULL)
{
*fp = fdopen (fd, mode);
if (*fp == NULL)
{
- saved_errno = errno;
+ saved_errno = errno;
msg (ME, _("Opening stream for %s: %s."),
file_name, strerror (saved_errno));
close (fd);
msg (ME, _("Opening stream for %s: %s."),
file_name, strerror (saved_errno));
close (fd);
@@
-268,7
+265,10
@@
replace_file_start (const struct file_handle *fh, const char *mode,
rf->tmp_name = convert_to_filename_encoding (rf->tmp_name_verbatim, strlen (rf->tmp_name_verbatim), fh_get_file_name_encoding (fh));
/* Create file by that name. */
rf->tmp_name = convert_to_filename_encoding (rf->tmp_name_verbatim, strlen (rf->tmp_name_verbatim), fh_get_file_name_encoding (fh));
/* Create file by that name. */
- fd = Topen (rf->tmp_name, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, permissions);
+ bool binary = strchr (mode, 'b') != NULL;
+ fd = Topen (rf->tmp_name,
+ O_WRONLY | O_CREAT | O_EXCL | (binary ? O_BINARY : O_TEXT),
+ permissions);
if (fd >= 0)
break;
if (errno != EEXIST)
if (fd >= 0)
break;
if (errno != EEXIST)
@@
-372,7
+372,7
@@
free_replace_file (struct replace_file *rf)
}
static void
}
static void
-unlink_replace_files (
void
)
+unlink_replace_files (
int sig UNUSED
)
{
struct replace_file *rf;
{
struct replace_file *rf;