char *md5sum_hex;
unsigned char md5sum_bin[md5sum_bin_len];
- md5sum_hex = malloc(md5sum_hex_len + 1);
+ md5sum_hex = calloc(1, md5sum_hex_len + 1);
if (md5sum_hex == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return strdup("");
return 0;
}
}
- hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
+ hash_entry->next = (hash_entry_t *)calloc(1, sizeof(hash_entry_t));
if (!hash_entry->next) {
return -ENOMEM;
}
return 0;
}
+int hash_table_remove(hash_table_t *hash, const char *key)
+{
+ int ndx= hash_index(hash, key);
+ hash_entry_t *hash_entry = hash->entries + ndx;
+ hash_entry_t *next_entry=NULL, *last_entry=NULL;
+ while (hash_entry)
+ {
+ if (hash_entry->key)
+ {
+ if (strcmp(key, hash_entry->key) == 0) {
+ free(hash_entry->key);
+ if (last_entry) {
+ last_entry->next = hash_entry->next;
+ free(hash_entry);
+ } else {
+ next_entry = hash_entry->next;
+ if (next_entry) {
+ memmove(hash_entry, next_entry, sizeof(hash_entry_t));
+ free(next_entry);
+ } else {
+ memset(hash_entry, 0 , sizeof(hash_entry_t));
+ }
+ }
+ return 1;
+ }
+ }
+ last_entry = hash_entry;
+ hash_entry = hash_entry->next;
+ }
+ return 0;
+}
void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
{
void hash_table_deinit(hash_table_t *hash);
void *hash_table_get(hash_table_t *hash, const char *key);
int hash_table_insert(hash_table_t *hash, const char *key, void *value);
+int hash_table_remove(hash_table_t *has, const char *key);
void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
#endif /* _HASH_TABLE_H_ */
int err;
/* freed in nv_pair_list_deinit */
- nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
+ nv_pair_t *nv_pair = calloc(1, sizeof(nv_pair_t));
if (nv_pair == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
opkg_package_t *p;
- p = malloc (sizeof (opkg_package_t));
- memset (p, 0, sizeof (opkg_package_t));
+ p = calloc (1, sizeof (opkg_package_t));
return p;
}
opkg_t *opkg;
int err;
- opkg = malloc (sizeof (opkg_t));
+ opkg = calloc (1, sizeof (opkg_t));
- opkg->args = malloc (sizeof (args_t));
+ opkg->args = calloc (1, sizeof (args_t));
err = args_init (opkg->args);
if (err)
{
return NULL;
}
- opkg->conf = malloc (sizeof (opkg_conf_t));
+ opkg->conf = calloc (1, sizeof (opkg_conf_t));
err = opkg_conf_init (opkg->conf, opkg->args);
if (err)
{
char *newpath;
int gen;
- ctx = malloc (sizeof (*ctx));
+ ctx = calloc (1, sizeof (*ctx));
oldpath = getenv ("PATH");
if (oldpath) {
ctx->oldpath = strdup (oldpath);
available = pkg_vec_alloc();
pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
for (i=0; i < argc; i++) {
- pkg_name = malloc(strlen(argv[i])+2);
+ pkg_name = calloc(1, strlen(argv[i])+2);
strcpy(pkg_name,argv[i]);
for (a=0; a < available->len; a++) {
pkg = available->pkgs[a];
size_t used_len;
char *buff ;
- buff = (char *)malloc(buff_len);
+ buff = (char *)calloc(1, buff_len);
if ( buff == NULL ) {
fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
return ENOMEM;
{ NULL }
};
- *options = (opkg_option_t *)malloc(sizeof(tmp));
+ *options = (opkg_option_t *)calloc(1, sizeof(tmp));
if ( options == NULL ){
fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
return -1;
lists_dir = tmp;
}
- pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
+ pending_dir = calloc(1, strlen(lists_dir)+strlen("/pending")+5);
snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
conf->lists_dir = strdup(lists_dir);
if (found)
continue;
d_str = old_pkg->depends_str[i];
- buf = malloc (strlen (d_str) + 1);
+ buf = calloc (1, strlen (d_str) + 1);
j=0;
while (d_str[j] != '\0' && d_str[j] != ' ') {
buf[j]=d_str[j];
/* if caller requested the set of installed dependents */
if (pdependents) {
int p = 0;
- abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
+ abstract_pkg_t **dependents = (abstract_pkg_t **)calloc((n_installed_dependents+1), sizeof(abstract_pkg_t *));
if ( dependents == NULL ){
fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
int x = 0;
pkg_t *p;
d_str = pkg->depends_str[i];
- buffer = malloc (strlen (d_str) + 1);
+ buffer = calloc (1, strlen (d_str) + 1);
if (!buffer)
{
fprintf(stderr,"%s Unable to allocate memory.\n", __FUNCTION__);
int count = 0;
size_t size = 512;
- buf = malloc (size);
+ buf = calloc (1, size);
while (fgets(buf, size, fp)) {
while (strlen (buf) == (size - 1)
char *new;
char *dest, *src, *end;
- new = malloc(strlen(line) + 1);
+ new = calloc(1, strlen(line) + 1);
if ( new == NULL ){
fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
return NULL;
struct errlist *err_lst_tmp;
- err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
+ err_lst_tmp = calloc (1, sizeof (err_lst_tmp) );
err_lst_tmp->errmsg=strdup(msg) ;
err_lst_tmp->next = *errors;
*errors = err_lst_tmp;
{
pkg_t *pkg;
- pkg = malloc(sizeof(pkg_t));
+ pkg = calloc(1, sizeof(pkg_t));
if (pkg == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return NULL;
{
abstract_pkg_t * ab_pkg;
- ab_pkg = malloc(sizeof(abstract_pkg_t));
+ ab_pkg = calloc(1, sizeof(abstract_pkg_t));
if (ab_pkg == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
char **raw =NULL;
char **raw_start=NULL;
- temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
+ temp_str = (char *) calloc (1, strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
if (temp_str == NULL ){
opkg_message(conf, OPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
return;
char *line;
char * buff;
- buff = malloc(8192);
+ buff = calloc(1, 8192);
if (buff == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return NULL;
str_list_elt_t *iter;
pkg->installed_files_ref_cnt--;
- if (pkg->installed_files_ref_cnt > 0) {
+
+ if (pkg->installed_files_ref_cnt > 0)
return 0;
- }
if (pkg->installed_files) {
if (pkg->provides)
return 0;
- pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
+ pkg->provides = (abstract_pkg_t **)calloc((pkg->provides_count + 1), sizeof(abstract_pkg_t *));
if (pkg->provides == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return -1 ;
if (!pkg->conflicts_count)
return 0;
- conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
- pkg->conflicts_count);
+ conflicts = pkg->conflicts = calloc(pkg->conflicts_count, sizeof(compound_depend_t));
if (conflicts == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return -1;
if (!pkg->replaces_count)
return 0;
- pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
+ pkg->replaces = (abstract_pkg_t **)calloc(pkg->replaces_count, sizeof(abstract_pkg_t *));
if (pkg->replaces == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return -1;
if (0 && pkg->pre_depends_count)
fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
pkg->name, pkg->pre_depends_count, pkg->depends_count);
- depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
+ depends = pkg->depends = calloc(count, sizeof(compound_depend_t));
if (depends == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return -1;
static depend_t * depend_init(void)
{
- depend_t * d = (depend_t *)malloc(sizeof(depend_t));
+ depend_t * d = (depend_t *)calloc(1, sizeof(depend_t));
if ( d==NULL ){
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return NULL;
compound_depend->type = DEPEND;
compound_depend->possibility_count = num_of_ors + 1;
- possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
+ possibilities = (depend_t **)calloc((num_of_ors + 1), sizeof(depend_t *) );
if (!possibilities)
return -ENOMEM;
compound_depend->possibilities = possibilities;
pkg_dest_t *pkg_dest;
/* freed in plg_dest_list_deinit */
- pkg_dest = malloc(sizeof(pkg_dest_t));
+ pkg_dest = calloc(1, sizeof(pkg_dest_t));
if (pkg_dest == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return NULL;
if (!pkg->version)
{
- pkg->version= malloc(strlen(raw)+1);
+ pkg->version= calloc(1, strlen(raw)+1);
if ( pkg->version == NULL ) {
fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
return ENOMEM;
pkg->priority = parseGenericFieldType("Priority", *lines);
else if(isGenericFieldType("Provides", *lines)){
/* Here we add the internal_use to align the off by one problem between provides_str and provides */
- provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new opkg_internal_use_only */
+ provide = (char * ) calloc(1, strlen(*lines)+ 35 ); /* Preparing the space for the new opkg_internal_use_only */
if ( alterProvidesLine(*lines,provide) ){
return EINVAL;
}
if ( pkg_false_provides==1)
{
pkg->provides_count = 1;
- pkg->provides_str = malloc (sizeof (char*));
+ pkg->provides_str = calloc (1, sizeof (char*));
pkg->provides_str[0] = strdup ("opkg_internal_use_only");
}
int err;
/* freed in pkg_src_list_deinit */
- pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
+ pkg_src_t *pkg_src = calloc(1, sizeof(pkg_src_t));
if (pkg_src == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
*/
void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
{
-
- vec->pkgs =
- (abstract_pkg_t **)
- realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
- vec->pkgs[vec->len] = pkg;
- vec->len++;
+ vec->pkgs = (abstract_pkg_t **) realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
+ vec->pkgs[vec->len] = pkg;
+ vec->len++;
}
abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
/* ripped more or less straight out of PRINTF(3) */
- if ((new_str = malloc(size)) == NULL)
+ if ((new_str = calloc(1, size)) == NULL)
return -1;
*str = new_str;
str_list_t *str_list_alloc()
{
- str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
+ str_list_t *list = (str_list_t *)calloc(1, sizeof(str_list_t));
if (list)
str_list_init(list);
return list;
void_list_elt_t *elt;
/* freed in void_list_deinit */
- elt = malloc(sizeof(void_list_elt_t));
+ elt = calloc(1, sizeof(void_list_elt_t));
if (elt == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return ENOMEM;
{
void_list_elt_t *elt;
- elt = malloc(sizeof(void_list_elt_t));
+ elt = calloc(1, sizeof(void_list_elt_t));
if (elt == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return ENOMEM;
fprintf(stderr, "%s: Error compiling regex:", __FUNCTION__);
size = regerror(err, preg, 0, 0);
- error = malloc(size);
+ error = calloc(1, size);
if (error) {
regerror(err, preg, error, size);
fprintf(stderr, "%s\n", error);