diff options
-rw-r--r-- | articles.c | 32 | ||||
-rw-r--r-- | articles.h | 2 |
2 files changed, 25 insertions, 9 deletions
@@ -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 ); @@ -25,6 +25,8 @@ #include "libterm/term_io.h" #include "logs.h" +#include "sds.h" + //part of libadt #include "list.h" |