X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=fish%2Ffish.c;h=6aadd5608601af0bfee367c25c8330637c841313;hb=06397c2f1ffe56e2300ff9439a2903479c9c3da3;hp=9ca57be1d50f29ff1a408ba0b04b72c910eb5edd;hpb=ff4ae8633e0ca7c1e679870600830ee4d9f1cd71;p=libguestfs.git diff --git a/fish/fish.c b/fish/fish.c index 9ca57be..6aadd56 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -73,6 +73,8 @@ static void set_up_terminal (void); static char add_drives (struct drv *drv, char next_drive); static void prepare_drives (struct drv *drv); static void mount_mps (struct mp *mp); +static void free_drives (struct drv *drv); +static void free_mps (struct mp *mp); static int launch (void); static void interactive (void); static void shell_script (void); @@ -485,6 +487,10 @@ main (int argc, char *argv[]) mount_mps (mps); } + /* Free up data structures, no longer needed after this point. */ + free_drives (drvs); + free_mps (mps); + /* Remote control? */ if (remote_control_listen && remote_control) { fprintf (stderr, @@ -688,6 +694,38 @@ prepare_drives (struct drv *drv) } } +static void +free_drives (struct drv *drv) +{ + if (!drv) return; + free_drives (drv->next); + + switch (drv->type) { + case drv_a: /* a.filename is optarg, don't free it */ break; + case drv_d: /* d.filename is optarg, don't free it */ break; + case drv_N: + free (drv->N.filename); + free (drv->N.device); + free_prep_data (drv->N.data); + break; + default: ; /* keep GCC happy */ + } + free (drv); +} + +static void +free_mps (struct mp *mp) +{ + if (!mp) return; + free_mps (mp->next); + + /* The drive and mountpoint fields are not allocated + * from the heap, so we should not free them here. + */ + + free (mp); +} + static int launch (void) { @@ -1398,6 +1436,7 @@ cleanup_readline (void) #else (void) write_history (histfile); #endif + clear_history (); } #endif } @@ -1522,7 +1561,7 @@ file_in (const char *arg) static char * file_in_heredoc (const char *endmarker) { - static const char template[] = "/tmp/heredocXXXXXX"; + TMP_TEMPLATE_ON_STACK (template); file_in_tmpfile = strdup (template); if (file_in_tmpfile == NULL) { perror ("strdup");