aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2005-01-11 22:53:39 +0000
committerJason Woodward2005-01-11 22:53:39 +0000
commit45c0abb87683d2d4972c2228b4129f67ae24a13e (patch)
tree22324d1f703455f0228b44517e829eb801081341 /src
parent6e3035a1c6fd9112f99a34997ed831abbfc78ac7 (diff)
downloadslapt-get-45c0abb87683d2d4972c2228b4129f67ae24a13e.tar.gz
all malloc and calloc calls are now wrapped in slapt_malloc and slapt_calloc
Diffstat (limited to 'src')
-rw-r--r--src/action.c4
-rw-r--r--src/common.c24
-rw-r--r--src/common.h3
-rw-r--r--src/configuration.c21
-rw-r--r--src/curl.c8
-rw-r--r--src/main.c4
-rw-r--r--src/package.c62
-rw-r--r--src/transaction.c42
8 files changed, 77 insertions, 91 deletions
diff --git a/src/action.c b/src/action.c
index 6b9b8d3..3206177 100644
--- a/src/action.c
+++ b/src/action.c
@@ -577,8 +577,8 @@ void pkg_action_upgrade_all(const rc_config *global_config){
pkg_action_args_t *init_pkg_action_args(int arg_count){
pkg_action_args_t *paa;
- paa = malloc( sizeof *paa );
- paa->pkgs = malloc( sizeof *paa->pkgs * arg_count );
+ paa = slapt_malloc( sizeof *paa );
+ paa->pkgs = slapt_malloc( sizeof *paa->pkgs * arg_count );
paa->count = 0;
return paa;
diff --git a/src/common.c b/src/common.c
index 5de61ed..552ae02 100644
--- a/src/common.c
+++ b/src/common.c
@@ -92,7 +92,7 @@ void gen_md5_sum_of_file(FILE *f,char *result_sum){
result_sum[0] = '\0';
for(i = 0; i < md_len; i++){
- char *p = malloc( sizeof *p * 3 );
+ char *p = slapt_malloc( sizeof *p * 3 );
if( snprintf(p,3,"%02x",md_value[i]) > 0 ){
@@ -216,7 +216,7 @@ int ask_yes_no(const char *format, ...)
char *str_replace_chr(const char *string,const char find, const char replace){
unsigned int i,len = 0;
- char *clean = calloc( strlen(string) + 1, sizeof *clean);;
+ char *clean = slapt_calloc( strlen(string) + 1, sizeof *clean);;
len = strlen(string);
for(i = 0;i < len; ++i){
@@ -231,3 +231,23 @@ char *str_replace_chr(const char *string,const char find, const char replace){
return clean;
}
+__inline void *slapt_malloc(size_t s){
+ void *p;
+ if( ! (p = malloc(s)) ){
+ fprintf(stderr,_("Failed to malloc\n"));
+ if( errno ) perror("malloc");
+ exit(1);
+ }
+ return p;
+}
+
+__inline void *slapt_calloc(size_t n,size_t s){
+ void *p;
+ if( ! (p = calloc(n,s)) ){
+ fprintf(stderr,_("Failed to calloc\n"));
+ if( errno ) perror("calloc");
+ exit(1);
+ }
+ return p;
+}
+
diff --git a/src/common.h b/src/common.h
index f6147ac..98bbd9a 100644
--- a/src/common.h
+++ b/src/common.h
@@ -42,3 +42,6 @@ void gen_md5_sum_of_file(FILE *f,char *result_sum);
*/
int ask_yes_no(const char *format, ...);
char *str_replace_chr(const char *string,const char find, const char replace);
+__inline void *slapt_malloc(size_t s);
+__inline void *slapt_calloc(size_t n,size_t s);
+
diff --git a/src/configuration.c b/src/configuration.c
index 3aa6a2b..0fb9d69 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -28,13 +28,7 @@ rc_config *read_rc_config(const char *file_name){
size_t gb_length = 0;
ssize_t g_size;
- global_config = malloc( sizeof *global_config );
- if( global_config == NULL ){
- fprintf(stderr,_("Failed to malloc %s\n"),"global_config");
- if( errno ){
- perror("global_config malloc");
- }
- }
+ global_config = slapt_malloc( sizeof *global_config );
/* initialize */
global_config->sources.count = 0;
global_config->download_only = 0;
@@ -125,7 +119,7 @@ rc_config *read_rc_config(const char *file_name){
}
if( global_config->exclude_list == NULL ){
/* at least initialize */
- global_config->exclude_list = malloc( sizeof *global_config->exclude_list );
+ global_config->exclude_list = slapt_malloc( sizeof *global_config->exclude_list );
global_config->exclude_list->count = 0;
}
if( global_config->sources.count == 0 ){
@@ -177,15 +171,8 @@ static struct exclude_list *parse_exclude(char *line){
struct exclude_list *list;
unsigned int position = 0, len = 0;
- list = malloc( sizeof *list );
- if( list == NULL ){
- fprintf(stderr,_("Failed to malloc %s\n"),"list");
- if( errno ){
- perror("malloc");
- }
- exit(1);
- }
- list->excludes = malloc( sizeof *list->excludes );
+ list = slapt_malloc( sizeof *list );
+ list->excludes = slapt_malloc( sizeof *list->excludes );
list->count = 0;
/* skip ahead past the = */
diff --git a/src/curl.c b/src/curl.c
index dd2f67c..2e3f2d8 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -108,7 +108,7 @@ char *head_request(const char *url){
struct head_data_t head_t;
struct curl_slist *headers = NULL;
- head_t.data = malloc( sizeof *head_t.data );
+ head_t.data = slapt_malloc( sizeof *head_t.data );
head_t.size = 0;
ch = curl_easy_init();
@@ -145,13 +145,9 @@ int get_mirror_data_from_source(FILE *fh,int use_curl_dl_stats,const char *base_
int return_code = 0;
char *url = NULL;
- url = calloc(
+ url = slapt_calloc(
strlen(base_url) + strlen(filename) + 1, sizeof *url
);
- if( url == NULL ){
- fprintf(stderr,_("Failed to calloc %s\n"),"url");
- exit(1);
- }
strncpy(url,base_url,strlen(base_url) );
url[ strlen(base_url) ] = '\0';
diff --git a/src/main.c b/src/main.c
index 78b9a8b..d701cc5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -213,7 +213,7 @@ int main( int argc, char *argv[] ){
case INSTALL:
paa = init_pkg_action_args((argc - optind));
while (optind < argc){
- paa->pkgs[paa->count] = malloc(
+ paa->pkgs[paa->count] = slapt_malloc(
( strlen(argv[optind]) + 1 ) * sizeof *paa->pkgs[paa->count]
);
memcpy(paa->pkgs[paa->count],argv[optind],strlen(argv[optind]) + 1);
@@ -226,7 +226,7 @@ int main( int argc, char *argv[] ){
case REMOVE:
paa = init_pkg_action_args((argc - optind));
while (optind < argc){
- paa->pkgs[paa->count] = malloc(
+ paa->pkgs[paa->count] = slapt_malloc(
( strlen(argv[optind]) + 1 ) * sizeof *paa->pkgs[paa->count]
);
memcpy(paa->pkgs[paa->count],argv[optind],strlen(argv[optind]) + 1);
diff --git a/src/package.c b/src/package.c
index 2e3e55c..1568fab 100644
--- a/src/package.c
+++ b/src/package.c
@@ -445,7 +445,7 @@ struct pkg_list *get_installed_pkgs(void){
if( strcspn(getenv(ROOT_ENV_NAME),NAUGHTY_CHARS) == 0 )
root_env_entry = getenv(ROOT_ENV_NAME);
}
- pkg_log_dirname = calloc(
+ pkg_log_dirname = slapt_calloc(
strlen(PKG_LOG_DIR)+
(root_env_entry ? strlen(root_env_entry) : 0) + 1 ,
sizeof *pkg_log_dirname
@@ -495,7 +495,7 @@ struct pkg_list *get_installed_pkgs(void){
tmp_pkg->version[ ip_regex.pmatch[2].rm_eo - ip_regex.pmatch[2].rm_so ] = '\0';
/* build the package filename including the package directory */
- pkg_f_name = malloc( sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(file->d_name) + 2) );
+ pkg_f_name = slapt_malloc( sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(file->d_name) + 2) );
pkg_f_name[0] = '\0';
strncat(pkg_f_name,pkg_log_dirname,strlen(pkg_log_dirname));
strncat(pkg_f_name,"/",strlen("/"));
@@ -600,7 +600,7 @@ int install_pkg(const rc_config *global_config,pkg_info_t *pkg){
pkg_file_name = gen_pkg_file_name(global_config,pkg);
/* build and execute our command */
- command = calloc( strlen(INSTALL_CMD) + strlen(pkg_file_name) + 1 , sizeof *command );
+ command = slapt_calloc( strlen(INSTALL_CMD) + strlen(pkg_file_name) + 1 , sizeof *command );
command[0] = '\0';
command = strncat(command,INSTALL_CMD,strlen(INSTALL_CMD));
command = strncat(command,pkg_file_name,strlen(pkg_file_name));
@@ -627,7 +627,7 @@ int upgrade_pkg(const rc_config *global_config,pkg_info_t *installed_pkg,pkg_inf
pkg_file_name = gen_pkg_file_name(global_config,pkg);
/* build and execute our command */
- command = calloc( strlen(UPGRADE_CMD) + strlen(pkg_file_name) + 1 , sizeof *command );
+ command = slapt_calloc( strlen(UPGRADE_CMD) + strlen(pkg_file_name) + 1 , sizeof *command );
command[0] = '\0';
command = strncat(command,UPGRADE_CMD,strlen(UPGRADE_CMD));
command = strncat(command,pkg_file_name,strlen(pkg_file_name));
@@ -652,7 +652,7 @@ int remove_pkg(const rc_config *global_config,pkg_info_t *pkg){
(void)global_config;
/* build and execute our command */
- command = calloc(
+ command = slapt_calloc(
strlen(REMOVE_CMD) + strlen(pkg->name) + strlen("-") + strlen(pkg->version) + 1,
sizeof *command
);
@@ -916,8 +916,8 @@ static struct pkg_version_parts *break_down_pkg_version(const char *version){
char *pointer,*short_version;
struct pkg_version_parts *pvp;
- pvp = malloc( sizeof *pvp );
- pvp->parts = malloc( sizeof *pvp->parts );
+ pvp = slapt_malloc( sizeof *pvp );
+ pvp->parts = slapt_malloc( sizeof *pvp->parts );
pvp->count = 0;
/* generate a short version, leave out arch and release */
@@ -925,7 +925,7 @@ static struct pkg_version_parts *break_down_pkg_version(const char *version){
return pvp;
}else{
sv_size = ( strlen(version) - strlen(pointer) + 1);
- short_version = malloc( sizeof *short_version * sv_size );
+ short_version = slapt_malloc( sizeof *short_version * sv_size );
memcpy(short_version,version,sv_size);
short_version[sv_size - 1] = '\0';
pointer = NULL;
@@ -944,7 +944,7 @@ static struct pkg_version_parts *break_down_pkg_version(const char *version){
/* check for . as a seperator */
if( (pointer = strchr(short_version + pos,'.')) != NULL ){
int b_count = ( strlen(short_version + pos) - strlen(pointer) + 1 );
- pvp->parts[pvp->count] = malloc( sizeof *pvp->parts[pvp->count] * b_count );
+ pvp->parts[pvp->count] = slapt_malloc( sizeof *pvp->parts[pvp->count] * b_count );
memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
pvp->parts[pvp->count][b_count - 1] = '\0';
++pvp->count;
@@ -953,7 +953,7 @@ static struct pkg_version_parts *break_down_pkg_version(const char *version){
/* check for _ as a seperator */
}else if( (pointer = strchr(short_version + pos,'_')) != NULL ){
int b_count = ( strlen(short_version + pos) - strlen(pointer) + 1 );
- pvp->parts[pvp->count] = malloc( sizeof *pvp->parts[pvp->count] * b_count );
+ pvp->parts[pvp->count] = slapt_malloc( sizeof *pvp->parts[pvp->count] * b_count );
memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
pvp->parts[pvp->count][b_count - 1] = '\0';
++pvp->count;
@@ -962,7 +962,7 @@ static struct pkg_version_parts *break_down_pkg_version(const char *version){
/* must be the end of the string */
}else{
int b_count = ( strlen(short_version + pos) + 1 );
- pvp->parts[pvp->count] = malloc( sizeof *pvp->parts[pvp->count] * b_count );
+ pvp->parts[pvp->count] = slapt_malloc( sizeof *pvp->parts[pvp->count] * b_count );
memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
pvp->parts[pvp->count][b_count - 1] = '\0';
++pvp->count;
@@ -1477,7 +1477,7 @@ char *head_mirror_data(const char *wurl,const char *file){
char *url;
/* build url */
- url = calloc( strlen(wurl) + strlen(file) + 2, sizeof *url );
+ url = slapt_calloc( strlen(wurl) + strlen(file) + 2, sizeof *url );
url[0] = '\0';
strncat(url,wurl,strlen(wurl));
strncat(url,"/",1);
@@ -1507,7 +1507,7 @@ char *head_mirror_data(const char *wurl,const char *file){
}
request_header_len = strlen(request_header_ptr) - strlen(delim_ptr);
- request_header = calloc( request_header_len + 1, sizeof *request_header );
+ request_header = slapt_calloc( request_header_len + 1, sizeof *request_header );
memcpy(request_header,request_header_ptr,request_header_len);
free(head_data);
@@ -1556,7 +1556,7 @@ char *read_head_cache(const char *cache_filename){
char *gen_head_cache_filename(const char *filename_from_url){
char *head_filename;
- head_filename = calloc( strlen(filename_from_url) + strlen(HEAD_FILE_EXT) + 1, sizeof *head_filename );
+ head_filename = slapt_calloc( strlen(filename_from_url) + strlen(HEAD_FILE_EXT) + 1, sizeof *head_filename );
strncat(head_filename,filename_from_url,strlen(filename_from_url));
strncat(head_filename,HEAD_FILE_EXT,strlen(HEAD_FILE_EXT));
@@ -1769,12 +1769,8 @@ int update_pkg_cache(const rc_config *global_config){
struct pkg_list *init_pkg_list(void){
struct pkg_list *list;
- list = malloc( sizeof *list );
- list->pkgs = malloc( sizeof *list->pkgs );
- if( list->pkgs == NULL ){
- fprintf(stderr,_("Failed to malloc %s\n"),"list");
- exit(1);
- }
+ list = slapt_malloc( sizeof *list );
+ list->pkgs = slapt_malloc( sizeof *list->pkgs );
list->pkg_count = 0;
return list;
@@ -1799,11 +1795,7 @@ void add_pkg_to_pkg_list(struct pkg_list *list,pkg_info_t *pkg){
pkg_info_t *init_pkg(void){
pkg_info_t *pkg;
- pkg = malloc( sizeof *pkg );
- if( pkg == NULL ){
- fprintf(stderr,_("Failed to malloc %s\n"),"pkg");
- exit(1);
- }
+ pkg = slapt_malloc( sizeof *pkg );
pkg->size_c = 0;
pkg->size_u = 0;
@@ -1826,16 +1818,12 @@ char *gen_pkg_file_name(const rc_config *global_config,pkg_info_t *pkg){
char *file_name = NULL;
/* build the file name */
- file_name = calloc(
+ file_name = slapt_calloc(
strlen(global_config->working_dir)+strlen("/")
+strlen(pkg->location)+strlen("/")
+strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 ,
sizeof *file_name
);
- if( file_name == NULL ){
- fprintf(stderr,_("Failed to calloc %s\n"),"file_name");
- exit(1);
- }
file_name = strncpy(file_name,
global_config->working_dir,strlen(global_config->working_dir)
);
@@ -1857,28 +1845,20 @@ char *gen_pkg_url(pkg_info_t *pkg){
char *file_name = NULL;
/* build the file name */
- file_name = calloc(
+ file_name = slapt_calloc(
strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 ,
sizeof *file_name
);
- if( file_name == NULL ){
- fprintf(stderr,_("Failed to calloc %s\n"),"file_name");
- exit(1);
- }
file_name = strncpy(file_name,pkg->name,strlen(pkg->name));
file_name = strncat(file_name,"-",strlen("-"));
file_name = strncat(file_name,pkg->version,strlen(pkg->version));
file_name = strncat(file_name,".tgz",strlen(".tgz"));
- url = calloc(
+ url = slapt_calloc(
strlen(pkg->mirror) + strlen(pkg->location)
+ strlen(file_name) + strlen("/") + 1,
sizeof *url
);
- if( url == NULL ){
- fprintf(stderr,_("Failed to calloc %s\n"),"url");
- exit(1);
- }
url = strncpy(url,pkg->mirror,strlen(pkg->mirror));
url[ strlen(pkg->mirror) ] = '\0';
@@ -1956,7 +1936,7 @@ int verify_downloaded_pkg(const rc_config *global_config,pkg_info_t *pkg){
char *gen_filename_from_url(const char *url,const char *file){
char *filename,*cleaned;
- filename = calloc( strlen(url) + strlen(file) + 2 , sizeof *filename );
+ filename = slapt_calloc( strlen(url) + strlen(file) + 2 , sizeof *filename );
filename[0] = '.';
strncat(filename,url,strlen(url));
strncat(filename,file,strlen(file));
diff --git a/src/transaction.c b/src/transaction.c
index 5844233..eaa3cc0 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -21,17 +21,17 @@ static void add_suggestion(transaction_t *tran, pkg_info_t *pkg);
void init_transaction(transaction_t *tran){
- tran->install_pkgs = malloc( sizeof *tran->install_pkgs );
- tran->remove_pkgs = malloc( sizeof *tran->remove_pkgs );
- tran->upgrade_pkgs = malloc( sizeof *tran->upgrade_pkgs );
- tran->exclude_pkgs = malloc( sizeof *tran->exclude_pkgs );
+ tran->install_pkgs = slapt_malloc( sizeof *tran->install_pkgs );
+ tran->remove_pkgs = slapt_malloc( sizeof *tran->remove_pkgs );
+ tran->upgrade_pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs );
+ tran->exclude_pkgs = slapt_malloc( sizeof *tran->exclude_pkgs );
- tran->install_pkgs->pkgs = malloc( sizeof *tran->install_pkgs->pkgs );
- tran->remove_pkgs->pkgs = malloc( sizeof *tran->remove_pkgs->pkgs );
- tran->upgrade_pkgs->pkgs = malloc( sizeof *tran->upgrade_pkgs->pkgs );
- tran->exclude_pkgs->pkgs = malloc( sizeof *tran->exclude_pkgs->pkgs );
+ tran->install_pkgs->pkgs = slapt_malloc( sizeof *tran->install_pkgs->pkgs );
+ tran->remove_pkgs->pkgs = slapt_malloc( sizeof *tran->remove_pkgs->pkgs );
+ tran->upgrade_pkgs->pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs->pkgs );
+ tran->exclude_pkgs->pkgs = slapt_malloc( sizeof *tran->exclude_pkgs->pkgs );
- tran->suggests = malloc(sizeof *tran->suggests );
+ tran->suggests = slapt_malloc(sizeof *tran->suggests );
tran->suggests[0] = '\0';
tran->install_pkgs->pkg_count = 0;
@@ -244,7 +244,7 @@ void add_install_to_transaction(transaction_t *tran,pkg_info_t *pkg){
if( tmp_list != NULL ){
tran->install_pkgs->pkgs = tmp_list;
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = malloc(
+ tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = slapt_malloc(
sizeof *tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]
);
memcpy(
@@ -277,7 +277,7 @@ void add_remove_to_transaction(transaction_t *tran,pkg_info_t *pkg){
if( tmp_list != NULL ){
tran->remove_pkgs->pkgs = tmp_list;
- tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = malloc(
+ tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = slapt_malloc(
sizeof *tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count]
);
memcpy(
@@ -308,7 +308,7 @@ void add_exclude_to_transaction(transaction_t *tran,pkg_info_t *pkg){
if( tmp_list != NULL ){
tran->exclude_pkgs->pkgs = tmp_list;
- tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = malloc(
+ tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = slapt_malloc(
sizeof *tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count]
);
memcpy(
@@ -341,13 +341,13 @@ void add_upgrade_to_transaction(
if( tmp_list != NULL ){
tran->upgrade_pkgs->pkgs = tmp_list;
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count] = malloc(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count] = slapt_malloc(
sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]
);
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed = malloc(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed = slapt_malloc(
sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed
);
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = malloc(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = slapt_malloc(
sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade
);
@@ -438,12 +438,12 @@ transaction_t *remove_from_transaction(transaction_t *tran,pkg_info_t *pkg){
if( search_transaction(tran,pkg) == 0 )
return tran;
- /* since this is a pointer, malloc before calling init */
- new_tran = malloc(sizeof *new_tran);
- new_tran->install_pkgs = malloc( sizeof *new_tran->install_pkgs );
- new_tran->remove_pkgs = malloc( sizeof *new_tran->remove_pkgs );
- new_tran->upgrade_pkgs = malloc( sizeof *new_tran->upgrade_pkgs );
- new_tran->exclude_pkgs = malloc( sizeof *new_tran->exclude_pkgs );
+ /* since this is a pointer, slapt_malloc before calling init */
+ new_tran = slapt_malloc(sizeof *new_tran);
+ new_tran->install_pkgs = slapt_malloc( sizeof *new_tran->install_pkgs );
+ new_tran->remove_pkgs = slapt_malloc( sizeof *new_tran->remove_pkgs );
+ new_tran->upgrade_pkgs = slapt_malloc( sizeof *new_tran->upgrade_pkgs );
+ new_tran->exclude_pkgs = slapt_malloc( sizeof *new_tran->exclude_pkgs );
init_transaction(new_tran);
for(i = 0;i < tran->install_pkgs->pkg_count; i++){