summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--articles.c32
-rw-r--r--articles.h2
2 files changed, 25 insertions, 9 deletions
diff --git a/articles.c b/articles.c
index d651069..7db8b39 100644
--- a/articles.c
+++ b/articles.c
@@ -135,25 +135,24 @@ int bbs_article_list( term_screen *ts, const char *dir_name )
int cnt;
for ( cnt=0; cnt<n; cnt++)
{
- size_t tmp_size = strlen( eps[cnt]->d_name );
- char *cnct_path = malloc( tmp_size + strlen(dir_name)+1);
- memcpy( cnct_path, dir_name, strlen(dir_name));
- memcpy( cnct_path+sizeof(dir_name)+2, eps[cnt]->d_name,
- tmp_size+1 );
+ sds d_name = sds_new( eps[cnt]->d_name );
+ sds pathname = sds_new( dir_name );
+ pathname = sds_cat( pathname, d_name );
+ sds_free( d_name );
//check if its file
- if ( stat( cnct_path, &path_node ) == 0 )
+ if ( stat( pathname, &path_node ) == 0 )
{
if ( path_node.st_mode & S_IFREG )
{
- llist_push( dir_list, cnct_path );
+ llist_push( dir_list, pathname );
} else
{
- free( cnct_path );
+ sds_free( pathname );
}
} else
{
- free( cnct_path );
+ sds_free( pathname );
}
free( eps[cnt] );
}
@@ -240,7 +239,22 @@ int bbs_article_list( term_screen *ts, const char *dir_name )
printf("Try more\n");
}
}
+ //needed special care to free sds strings
+ //dangerous stuff as list contains sds strings then we need to call sds_free
+ //not just free, maybe try to use llist_manager it should handle that
+ {
+ struct ListNode *iter=dir_list->first;
+ while (iter != NULL)
+ {
+ if ( iter->val != NULL )
+ {
+ sds_free( iter->val );
+ iter->val = NULL;
+ }
+ iter = iter->next;
+ }
+ }
llist_free( dir_list );
diff --git a/articles.h b/articles.h
index 2240904..a0ad530 100644
--- a/articles.h
+++ b/articles.h
@@ -25,6 +25,8 @@
#include "libterm/term_io.h"
#include "logs.h"
+#include "sds.h"
+
//part of libadt
#include "list.h"