aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKalle Wallin <kaw@linux.se>2004-03-28 21:27:11 +0000
committerKalle Wallin <kaw@linux.se>2004-03-28 21:27:11 +0000
commit8a7c44223cbea87ef27a2f9f876a2cdaba8abec3 (patch)
tree18b79715c5c40be941496cfd0758ce7341da5f30
parente77407bf104d05c537f8f556ad9702ea98224d3c (diff)
downloadmpd-8a7c44223cbea87ef27a2f9f876a2cdaba8abec3.tar.gz
mpd-8a7c44223cbea87ef27a2f9f876a2cdaba8abec3.tar.xz
mpd-8a7c44223cbea87ef27a2f9f876a2cdaba8abec3.zip
We now allocate and free memory with glib
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@526 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--conf.c6
-rw-r--r--list_window.c4
-rw-r--r--main.c1
-rw-r--r--mpc.c23
-rw-r--r--options.c5
-rw-r--r--screen.c10
-rw-r--r--screen_file.c32
-rw-r--r--screen_play.c6
-rw-r--r--screen_utils.c4
9 files changed, 45 insertions, 46 deletions
diff --git a/conf.c b/conf.c
index 12fc15a61..170da5e5e 100644
--- a/conf.c
+++ b/conf.c
@@ -6,6 +6,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+
+#include <glib.h>
#include <ncurses.h>
#include "config.h"
@@ -104,7 +106,7 @@ read_rc_file(char *filename, options_t *options)
{
D(perror(filename));
if( free_filename )
- free(filename);
+ g_free(filename);
return -1;
}
@@ -248,7 +250,7 @@ read_rc_file(char *filename, options_t *options)
D(printf( "--\n\n" ));
if( free_filename )
- free(filename);
+ g_free(filename);
return 0;
}
diff --git a/list_window.c b/list_window.c
index d976ce05c..b04b817da 100644
--- a/list_window.c
+++ b/list_window.c
@@ -14,7 +14,7 @@ list_window_init(WINDOW *w, int width, int height)
{
list_window_t *lw;
- lw = malloc(sizeof(list_window_t));
+ lw = g_malloc(sizeof(list_window_t));
memset(lw, 0, sizeof(list_window_t));
lw->w = w;
lw->cols = width;
@@ -29,7 +29,7 @@ list_window_free(list_window_t *lw)
if( lw )
{
memset(lw, 0, sizeof(list_window_t));
- free(lw);
+ g_free(lw);
}
return NULL;
}
diff --git a/main.c b/main.c
index 0bfcb7434..56c18a316 100644
--- a/main.c
+++ b/main.c
@@ -28,6 +28,7 @@ exit_and_cleanup(void)
fprintf(stderr,"Error: %s\n", mpc_error_str(mpc));
mpc_close(mpc);
}
+ g_free(options.host);
}
void
diff --git a/mpc.c b/mpc.c
index f48d83cd7..785117fc9 100644
--- a/mpc.c
+++ b/mpc.c
@@ -1,8 +1,3 @@
-/*
- * $Id: mpc.c,v 1.5 2004/03/17 23:19:21 kalle Exp $
- *
- */
-
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -62,7 +57,7 @@ mpc_close(mpd_client_t *c)
if( c->connection )
mpd_closeConnection(c->connection);
if( c->cwd )
- free( c->cwd );
+ g_free( c->cwd );
return 0;
}
@@ -80,10 +75,10 @@ mpc_connect(char *host, int port)
exit(EXIT_FAILURE);
}
- c = malloc(sizeof(mpd_client_t));
+ c = g_malloc(sizeof(mpd_client_t));
memset(c, 0, sizeof(mpd_client_t));
c->connection = connection;
- c->cwd = strdup("");
+ c->cwd = g_strdup("");
return c;
}
@@ -228,20 +223,20 @@ mpc_get_song_name(mpd_Song *song)
snprintf(buf, MAX_SONG_LENGTH, "%s - %s", song->artist, song->title);
name = utf8_to_locale(buf);
strncpy(buf, name, MAX_SONG_LENGTH);
- free(name);
+ g_free(name);
return buf;
}
else
{
name = utf8_to_locale(song->title);
strncpy(buf, name, MAX_SONG_LENGTH);
- free(name);
+ g_free(name);
return buf;
}
}
name = utf8_to_locale(basename(song->file));
strncpy(buf, name, MAX_SONG_LENGTH);
- free(name);
+ g_free(name);
return buf;
}
@@ -294,7 +289,7 @@ mpc_free_filelist(mpd_client_t *c)
if( entry->entity )
mpd_freeInfoEntity(entry->entity);
- free(entry);
+ g_free(entry);
list=list->next;
}
g_list_free(c->filelist);
@@ -325,7 +320,7 @@ mpc_update_filelist(mpd_client_t *c)
if( c->cwd && c->cwd[0] )
{
/* add a dummy entry for ./.. */
- filelist_entry_t *entry = malloc(sizeof(filelist_entry_t));
+ filelist_entry_t *entry = g_malloc(sizeof(filelist_entry_t));
memset(entry, 0, sizeof(filelist_entry_t));
entry->entity = NULL;
c->filelist = g_list_append(c->filelist, (gpointer) entry);
@@ -334,7 +329,7 @@ mpc_update_filelist(mpd_client_t *c)
while( (entity=mpd_getNextInfoEntity(c->connection)) )
{
- filelist_entry_t *entry = malloc(sizeof(filelist_entry_t));
+ filelist_entry_t *entry = g_malloc(sizeof(filelist_entry_t));
memset(entry, 0, sizeof(filelist_entry_t));
entry->entity = entity;
diff --git a/options.c b/options.c
index f1840325b..cf3bbca27 100644
--- a/options.c
+++ b/options.c
@@ -3,6 +3,7 @@
#include <unistd.h>
#include <string.h>
#include <ncurses.h>
+#include <glib.h>
#include <popt.h>
#include "config.h"
@@ -98,9 +99,9 @@ options_init( void )
memset(&options, 0, sizeof(options_t));
if( (value=getenv(MPD_HOST_ENV)) )
- options.host = strdup(value);
+ options.host = g_strdup(value);
else
- options.host = strdup(DEFAULT_HOST);
+ options.host = g_strdup(DEFAULT_HOST);
if( (value=getenv(MPD_PORT_ENV)) )
options.port = atoi(value);
else
diff --git a/screen.c b/screen.c
index 3025d9a01..67ecc18bf 100644
--- a/screen.c
+++ b/screen.c
@@ -220,9 +220,9 @@ screen_exit(void)
screen->playlist = list_window_free(screen->playlist);
screen->filelist = list_window_free(screen->filelist);
screen->helplist = list_window_free(screen->helplist);
- free(screen->buf);
- free(screen->findbuf);
- free(screen);
+ g_free(screen->buf);
+ g_free(screen->findbuf);
+ g_free(screen);
screen = NULL;
}
return 0;
@@ -311,12 +311,12 @@ screen_init(void)
exit(EXIT_FAILURE);
}
- screen = malloc(sizeof(screen_t));
+ screen = g_malloc(sizeof(screen_t));
memset(screen, 0, sizeof(screen_t));
screen->mode = SCREEN_PLAY_WINDOW;
screen->cols = COLS;
screen->rows = LINES;
- screen->buf = malloc(screen->cols);
+ screen->buf = g_malloc(screen->cols);
screen->buf_size = screen->cols;
screen->findbuf = NULL;
screen->painted = 0;
diff --git a/screen_file.c b/screen_file.c
index c866566de..42d945617 100644
--- a/screen_file.c
+++ b/screen_file.c
@@ -15,7 +15,7 @@
#define BUFSIZE 1024
-#undef USE_OLD_LAYOUT
+#define USE_OLD_LAYOUT
static char *
list_callback(int index, int *highlight, void *data)
@@ -37,7 +37,7 @@ list_callback(int index, int *highlight, void *data)
#ifdef USE_OLD_LAYOUT
return "[..]";
#else
- return "<d> ..";
+ return "d ..";
#endif
}
if( entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY )
@@ -48,9 +48,9 @@ list_callback(int index, int *highlight, void *data)
#ifdef USE_OLD_LAYOUT
snprintf(buf, BUFSIZE, "[%s]", dirname);
#else
- snprintf(buf, BUFSIZE, "<d> %s", dirname);
+ snprintf(buf, BUFSIZE, "d %s", dirname);
#endif
- free(dirname);
+ g_free(dirname);
return buf;
}
else if( entity->type==MPD_INFO_ENTITY_TYPE_SONG )
@@ -58,9 +58,9 @@ list_callback(int index, int *highlight, void *data)
mpd_Song *song = entity->info.song;
#ifdef USE_OLD_LAYOUT
- return mpc_get_song_name(song));
+ return mpc_get_song_name(song);
#else
- snprintf(buf, BUFSIZE, "<m> %s", mpc_get_song_name(song));
+ snprintf(buf, BUFSIZE, "m %s", mpc_get_song_name(song));
return buf;
#endif
@@ -73,9 +73,9 @@ list_callback(int index, int *highlight, void *data)
#ifdef USE_OLD_LAYOUT
snprintf(buf, BUFSIZE, "*%s*", filename);
#else
- snprintf(buf, BUFSIZE, "<p> %s", filename);
+ snprintf(buf, BUFSIZE, "p %s", filename);
#endif
- free(filename);
+ g_free(filename);
return buf;
}
return "Error: Unknow entry!";
@@ -96,7 +96,7 @@ change_directory(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry)
parent[0] = '\0';
}
if( c->cwd )
- free(c->cwd);
+ g_free(c->cwd);
c->cwd = parent;
}
else
@@ -104,8 +104,8 @@ change_directory(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry)
{
mpd_Directory *dir = entity->info.directory;
if( c->cwd )
- free(c->cwd);
- c->cwd = strdup(dir->path);
+ g_free(c->cwd);
+ c->cwd = g_strdup(dir->path);
}
else
return -1;
@@ -126,7 +126,7 @@ load_playlist(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry)
mpd_finishCommand(c->connection);
screen_status_printf("Loading playlist %s...", filename);
- free(filename);
+ g_free(filename);
return 0;
}
@@ -156,7 +156,7 @@ handle_delete(screen_t *screen, mpd_client_t *c)
plf = entity->info.playlistFile;
str = utf8_to_locale(basename(plf->path));
snprintf(buf, BUFSIZE, "Delete playlist %s [y/n] ? ", str);
- free(str);
+ g_free(str);
key = tolower(screen_getch(screen->status_window.w, buf));
if( key!='y' )
{
@@ -170,7 +170,7 @@ handle_delete(screen_t *screen, mpd_client_t *c)
{
str = utf8_to_locale(mpc_error_str(c));
screen_status_printf("Error: %s", str);
- free(str);
+ g_free(str);
beep();
return -1;
}
@@ -210,7 +210,7 @@ add_directory(mpd_client_t *c, char *dir)
dirname = utf8_to_locale(dir);
screen_status_printf("Adding directory %s...\n", dirname);
- free(dirname);
+ g_free(dirname);
dirname = NULL;
mpd_sendLsInfoCommand(c->connection, dir);
@@ -356,7 +356,7 @@ file_get_header(mpd_client_t *c)
TOP_HEADER_FILE ": %s ",
tmp
);
- free(tmp);
+ g_free(tmp);
return buf;
}
diff --git a/screen_play.c b/screen_play.c
index 5f93ad093..72c223ed3 100644
--- a/screen_play.c
+++ b/screen_play.c
@@ -50,7 +50,7 @@ handle_save_playlist(screen_t *screen, mpd_client_t *c)
/* send save command to mpd */
mpd_sendSaveCommand(c->connection, filename_utf8);
mpd_finishCommand(c->connection);
- free(filename_utf8);
+ g_free(filename_utf8);
/* handle errors */
if( mpc_error(c))
{
@@ -58,7 +58,7 @@ handle_save_playlist(screen_t *screen, mpd_client_t *c)
{
char *str = utf8_to_locale(mpc_error_str(c));
screen_status_message(str);
- free(str);
+ g_free(str);
}
else
screen_status_printf("Error: Unable to save playlist as %s", filename);
@@ -68,7 +68,7 @@ handle_save_playlist(screen_t *screen, mpd_client_t *c)
}
/* success */
screen_status_printf("Saved %s", filename);
- free(filename);
+ g_free(filename);
/* update the file list if it has been initalized */
if( c->filelist )
{
diff --git a/screen_utils.c b/screen_utils.c
index 61c212edc..b93069c22 100644
--- a/screen_utils.c
+++ b/screen_utils.c
@@ -56,7 +56,7 @@ screen_getstr(WINDOW *w, char *prompt)
curs_set(1);
if( wgetnstr(w, buf, 256) == OK )
- line = strdup(buf);
+ line = g_strdup(buf);
noecho();
curs_set(0);
@@ -90,7 +90,7 @@ screen_find(screen_t *screen,
case CMD_LIST_RFIND:
if( screen->findbuf )
{
- free(screen->findbuf);
+ g_free(screen->findbuf);
screen->findbuf=NULL;
}
/* continue... */