Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Plug more memory leaks due to usage of g_strdup().

  • Loading branch information...
commit 0ebf48daaae1aedf948aeba990391f7829d7a6ee 1 parent e36e725
@erikd authored
View
10 src/file_sndfile1.c
@@ -67,7 +67,7 @@ typedef struct {
typedef struct {
gboolean saving; /* loading or saving ? */
sw_sample * sample;
- gchar * pathname;
+ gchar pathname [512];
SF_INFO * sfinfo;
GtkWidget * ok_button;
} sndfile_save_options;
@@ -484,7 +484,7 @@ sndfile_save_options_dialog (sw_sample * sample, gchar * pathname)
sfinfo->format = sample->file_format;
- so->pathname = g_strdup (pathname);
+ snprintf (so->pathname, sizeof (so->pathname), "%s", pathname);
so->sfinfo = sfinfo;
dialog = create_sndfile_encoding_options_dialog (so);
@@ -515,16 +515,14 @@ sndfile_load_options_dialog_ok_cb (GtkWidget * widget, gpointer data)
{
sndfile_save_options * so = (sndfile_save_options *)data;
sw_sample * sample = so->sample;
- gchar * pathname = so->pathname;
SF_INFO * sfinfo = so->sfinfo;
GtkWidget * dialog;
dialog = gtk_widget_get_toplevel (widget);
gtk_widget_destroy (dialog);
- _sndfile_sample_load (sample, pathname, sfinfo, TRUE);
+ _sndfile_sample_load (sample, so->pathname, sfinfo, TRUE);
- g_free (so->pathname);
g_free (so);
}
@@ -645,7 +643,7 @@ _sndfile_sample_load (sw_sample * sample, gchar * pathname, SF_INFO * sfinfo,
so = g_malloc0 (sizeof(*so));
so->saving = FALSE;
so->sample = sample;
- so->pathname = g_strdup (pathname);
+ snprintf (so->pathname, sizeof (so->pathname), "%s", pathname);
so->sfinfo = sfinfo;
sfinfo->format = (SF_FORMAT_RAW | SF_FORMAT_PCM_S8);
View
12 src/file_vorbis.c
@@ -119,8 +119,8 @@ extern GtkStyle * style_bw;
typedef struct _sw_metadata sw_metadata;
struct _sw_metadata {
- char * name;
- char * content;
+ char name [128];
+ char content [512];
};
static sw_metadata *
@@ -139,8 +139,8 @@ vorbis_metadata_from_str (char * str)
if (str[i] == '=') {
str[i] = '\0';
meta = g_malloc (sizeof (sw_metadata));
- meta->name = g_strdup (str);
- meta->content = g_strdup (&str[i+1]);
+ snprintf (meta->name, sizeof (meta->name), "%s", str);
+ snprintf (meta->content, sizeof (meta->content), "%s", str + i +1);
break;
}
}
@@ -852,6 +852,7 @@ vorbis_encode_options_reset_cb (GtkWidget * widget, gpointer data)
GtkObject * quality_adj;
float quality;
long l, bitrate;
+ char temp [64];
dialog = gtk_widget_get_toplevel (widget);
@@ -869,7 +870,8 @@ vorbis_encode_options_reset_cb (GtkWidget * widget, gpointer data)
entry = GTK_WIDGET(g_object_get_data (G_OBJECT(dialog),
"nominal_bitrate_entry"));
bitrate = prefs_get_long (NOMINAL_KEY, DEFAULT_NOMINAL);
- gtk_entry_set_text (GTK_ENTRY (entry), g_strdup_printf ("%ld", bitrate));
+ snprintf (temp, sizeof (temp), "%ld", bitrate);
+ gtk_entry_set_text (GTK_ENTRY (entry), temp);
/* Max bitrate */
View
21 src/question_dialogs.c
@@ -189,8 +189,8 @@ question_dialog_new (sw_sample * sample, char * title, char * question,
/* Thread safe info dialogs */
typedef struct {
- char * title;
- char * message;
+ char title [256];
+ char message [512];
gpointer xpm_data;
} info_dialog_data;
@@ -203,9 +203,6 @@ do_info_dialog (gpointer data)
_("OK"), NULL, NULL, NULL,
NULL, NULL, id->xpm_data, TRUE);
- g_free (id->title);
- g_free (id->message);
-
return FALSE;
}
@@ -221,8 +218,8 @@ info_dialog_new (char * title, gpointer xpm_data, const char * fmt, ...)
va_end (ap);
id = g_malloc (sizeof (info_dialog_data));
- id->title = g_strdup (title);
- id->message = g_strdup (buf);
+ snprintf (id->title, sizeof (id->title), "%s", title);
+ snprintf (id->message, sizeof (id->message), "%s", buf);
id->xpm_data = xpm_data;
sweep_timeout_add ((guint32)0, (GtkFunction)do_info_dialog, id);
@@ -252,7 +249,6 @@ syserror_dialog_new (gpointer data)
NULL, NULL, scrubby_system_xpm, TRUE);
}
- g_free (pd->message);
g_free (pd);
return FALSE;
@@ -263,15 +259,12 @@ sweep_perror (int thread_errno, const char * fmt, ...)
{
sweep_perror_data * pd;
va_list ap;
- char buf[512];
+
+ pd = g_malloc (sizeof (sweep_perror_data));
va_start (ap, fmt);
- vsnprintf (buf, sizeof (buf), fmt, ap);
+ snprintf (pd->message, sizeof (pd->message), fmt, ap);
va_end (ap);
- pd = g_malloc (sizeof (sweep_perror_data));
- pd->thread_errno = thread_errno;
- pd->message = g_strdup (buf);
-
sweep_timeout_add ((guint32)0, (GtkFunction)syserror_dialog_new, pd);
}
View
2  src/sweep_app.h
@@ -255,7 +255,7 @@ struct _sw_sample {
gint playmarker_tag; /* gtk_timeout tag for playmarkers */
gboolean tmp_message_active;
- gchar * last_tmp_message;
+ gchar last_tmp_message [512];
gint tmp_message_tag;
gint progress_ready_tag;
};
View
10 src/sweep_sample.c
@@ -177,7 +177,7 @@ sample_new_empty(gchar * pathname,
s->rec_head = NULL;
s->tmp_message_active = FALSE;
- s->last_tmp_message = NULL;
+ s->last_tmp_message [0] = 0;
s->tmp_message_tag = -1;
s->progress_ready_tag = -1;
@@ -657,8 +657,7 @@ sample_destroy (sw_sample * s)
gtk_widget_destroy (s->info_clist);
if (s->last_tmp_message) {
- memset (s->last_tmp_message, 0, strlen (s->last_tmp_message));
- g_free (s->last_tmp_message);
+ memset (s->last_tmp_message, 0, sizeof (s->last_tmp_message));
}
memset (s, 0, sizeof (*s));
@@ -1229,8 +1228,7 @@ sample_clear_tmp_message (gpointer data)
if (sample->edit_state == SWEEP_EDIT_STATE_IDLE)
sample_set_progress_ready (sample);
- g_free (sample->last_tmp_message);
- sample->last_tmp_message = NULL;
+ sample->last_tmp_message [0] = 0;
sample->tmp_message_tag = -1;
@@ -1248,7 +1246,7 @@ sample_set_tmp_message (sw_sample * s, const char * fmt, ...)
va_end (ap);
s->tmp_message_active = TRUE;
- s->last_tmp_message = g_strdup (buf);
+ snprintf (s->last_tmp_message, sizeof (s->last_tmp_message), "%s", buf);
sweep_timeout_remove (s->tmp_message_tag);
s->tmp_message_tag =
Please sign in to comment.
Something went wrong with that request. Please try again.