Fixes from Roland: we may not g_free() strdup-ed text.

This commit is contained in:
Pavel Machek 2000-10-31 15:43:49 +00:00
parent 2b8546dc21
commit 55e56a1426
7 changed files with 69 additions and 9 deletions

View File

@ -1,3 +1,13 @@
2000-10-31 Pavel Machek <pavel@artax.karlin.mff.cuni.cz>
* ftpfs.c (dir_load): From Roland Mainz
<Roland.Mainz@informatik.med.uni-giessen.de>: add '.' and '..'
directories
* *.c: From Roland: it is not possible to g_free() something
allocated by strdup(), because g_malloc might be different for
malloc. Therefore wrapped strdup into g_strdup() wrapper.
2000-10-22 Andrew V. Samoilov <sav@bcs.zp.ua>
* samba/libsmb/nterr.c (nt_errs): constified

View File

@ -766,7 +766,7 @@ vfs_s_open (vfs *me, char *file, int flags, int mode)
ent = vfs_s_generate_entry (me, name, dir, 0755);
ino = ent->ino;
vfs_s_insert_entry (me, dir, ent);
ino->localname = tempnam (NULL, me->name);
ino->localname = g_tempnam (NULL, me->name);
was_changed = 1;
}
@ -935,7 +935,7 @@ vfs_s_retrieve_file(vfs *me, struct vfs_s_inode *ino)
memset(&fh, 0, sizeof(fh));
fh.ino = ino;
if (!(ino->localname = tempnam (NULL, me->name))) ERRNOR (ENOMEM, 0);
if (!(ino->localname = g_tempnam (NULL, me->name))) ERRNOR (ENOMEM, 0);
handle = open(ino->localname, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600);
if (handle == -1) {
@ -1185,3 +1185,20 @@ vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd)
buffer [size-1] = 0;
return 0;
}
/* Roland: on most non-GNU/Linux platforms malloc()!=g_malloc() which
* may cause crashes. This wrapper ensures that memory from tempnam
* can safely free'ed with g_free()
*/
char *
g_tempnam( const char *dir, const char *prefix )
{
char *tmp = (char *)tempnam( dir, prefix );
char *name;
name = g_strdup( tmp );
free( tmp );
return( name );
}

View File

@ -605,7 +605,7 @@ static void *extfs_open (vfs *me, char *file, int flags, int mode)
char *cmd;
char *archive_name, *p;
entry->inode->local_filename = tempnam (NULL, "extfs");
entry->inode->local_filename = g_tempnam (NULL, "extfs");
{
int handle;

View File

@ -1219,7 +1219,31 @@ dir_load(vfs *me, vfs_s_inode *dir, char *remote_path)
/* Clear the interrupt flag */
enable_interrupt_key ();
#if 1
{
/* added 20001006 by gisburn
* add dots '.' and '..'. This must be _executed_ before scanning the dir as the
* code below may jump directly into error handling code (without executing
* remaining code). And C doesn't have try {...} finally {}; :-)
*/
vfs_s_inode *parent = dir->ent->dir;
if( parent==NULL )
parent = dir;
ent = vfs_s_generate_entry(me, ".", dir, 0);
ent->ino->st=dir->st;
num_entries++;
vfs_s_insert_entry(me, dir, ent);
ent = vfs_s_generate_entry(me, "..", parent, 0);
ent->ino->st=parent->st;
num_entries++;
vfs_s_insert_entry(me, dir, ent);
}
#endif
while (1) {
int i;
int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), sock);
@ -1729,6 +1753,7 @@ static int netrc_next (void)
static const char * const keywords [] = { "default", "machine",
"login", "password", "passwd", "account", "macdef" };
while (1) {
netrcp = skip_separators (netrcp);
if (*netrcp != '\n')

View File

@ -330,7 +330,7 @@ _get_file_entry(struct connection *bucket, char *file_name,
ent->local_filename = NULL;
}
if (flags & O_TRUNC) {
ent->local_filename = tempnam (NULL, X "fs");
ent->local_filename = g_tempnam (NULL, X "fs");
if (ent->local_filename == NULL) ERRNOR (ENOMEM, NULL);
handle = open(ent->local_filename, O_CREAT | O_TRUNC | O_RDWR | O_EXCL, 0600);
if (handle < 0) ERRNOR (EIO, NULL);
@ -368,7 +368,7 @@ _get_file_entry(struct connection *bucket, char *file_name,
ent->bucket = bucket;
ent->name = g_strdup(p);
ent->remote_filename = g_strdup(file_name);
ent->local_filename = tempnam (NULL, X "fs");
ent->local_filename = g_tempnam (NULL, X "fs");
if (!ent->name || !ent->remote_filename || !ent->local_filename) {
direntry_destructor(ent);
ERRNOR (ENOMEM, NULL);
@ -841,7 +841,7 @@ static int retrieve_file(struct direntry *fe)
if (fe->local_filename)
return 1;
if (!(fe->local_filename = tempnam (NULL, X))) ERRNOR (ENOMEM, 0);
if (!(fe->local_filename = g_tempnam (NULL, X))) ERRNOR (ENOMEM, 0);
fe->local_is_temp = 1;
local_handle = open(fe->local_filename, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600);

View File

@ -1060,7 +1060,7 @@ mc_def_getlocalcopy (vfs *vfs, char *filename)
fdin = mc_open (filename, O_RDONLY);
if (fdin == -1)
return NULL;
tmp = tempnam (NULL, "mclocalcopy");
tmp = g_tempnam (NULL, "mclocalcopy");
fdout = open (tmp, O_CREAT|O_WRONLY|O_TRUNC|O_EXCL, 0600);
if (fdout == -1)
goto fail;

View File

@ -254,12 +254,20 @@ int vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd);
/* misc */
int vfs_s_retrieve_file (vfs *me, struct vfs_s_inode *ino);
/* alloc temp name which can be safely free'd with g_free() */
char *g_tempnam( const char *dir, const char *prefix );
#if 0
/* If non-null, FREE */
#define ifree(ptr) do { if (ptr) g_free(ptr); } while (0)
#define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
#else
#define ifree(ptr) { if (ptr) g_free(ptr); }
#define ERRNOR(a, b) { me->verrno = a; return b; }
#endif
#define MEDATA ((struct vfs_s_data *) me->data)
#define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
#define FH ((struct vfs_s_fh *) fh)
#define FH_SUPER FH->ino->super