dropped the MALLOC macro

This commit is contained in:
Aurelien Foret 2006-02-20 20:41:40 +00:00
parent a5f67ef819
commit 590f610d6b
4 changed files with 27 additions and 18 deletions

View File

@ -57,7 +57,8 @@ static int add_faketarget(pmtrans_t *trans, char *name)
char *str = NULL;
pmpkg_t *dummy = NULL;
if((dummy = _alpm_pkg_new(NULL, NULL)) == NULL) {
dummy = _alpm_pkg_new(NULL, NULL);
if(dummy == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
@ -457,7 +458,10 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
if(!strcmp(file, pathname)) {
char *fn;
/* 32 for the hash, 1 for the terminating NULL, and 1 for the tab delimiter */
MALLOC(fn, strlen(file)+34);
fn = (char *)malloc(strlen(file)+34);
if(fn == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
sprintf(fn, "%s\t%s", file, md5_pkg);
FREE(file);
lp->data = fn;
@ -568,7 +572,10 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
snprintf(path, PATH_MAX, "%s%s", handle->root, file);
md5 = MDFile(path);
/* 32 for the hash, 1 for the terminating NULL, and 1 for the tab delimiter */
MALLOC(fn, strlen(file)+34);
fn = (char *)malloc(strlen(file)+34);
if(fn == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
sprintf(fn, "%s\t%s", file, md5);
FREE(md5);
FREE(file);

View File

@ -32,6 +32,7 @@
/* pacman */
#include "log.h"
#include "util.h"
#include "error.h"
#include "group.h"
#include "cache.h"
#include "db.h"
@ -48,9 +49,15 @@ pmdb_t *_alpm_db_open(char *dbpath, char *treename, int mode)
_alpm_log(PM_LOG_DEBUG, "opening database '%s'", treename);
MALLOC(db, sizeof(pmdb_t));
db = (pmdb_t *)malloc(sizeof(pmdb_t));
if(db == NULL) {
RET_ERR(PM_ERR_MEMORY, NULL);
}
MALLOC(db->path, strlen(dbpath)+strlen(treename)+2);
db->path = (char *)malloc(strlen(dbpath)+strlen(treename)+2);
if(db->path == NULL) {
RET_ERR(PM_ERR_MEMORY, NULL);
}
sprintf(db->path, "%s/%s", dbpath, treename);
db->dir = opendir(db->path);

View File

@ -39,7 +39,10 @@ pmpkg_t *_alpm_pkg_new(const char *name, const char *version)
{
pmpkg_t* pkg = NULL;
MALLOC(pkg, sizeof(pmpkg_t));
pkg = (pmpkg_t *)malloc(sizeof(pmpkg_t));
if(pkg == NULL) {
RET_ERR(PM_ERR_MEMORY, NULL);
}
if(name && name[0] != 0) {
STRNCPY(pkg->name, name, PKG_NAME_LEN);
@ -313,7 +316,10 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile)
char *str;
int fd;
MALLOC(str, PATH_MAX);
str = (char *)malloc(PATH_MAX);
if(str == NULL) {
RET_ERR(PM_ERR_MEMORY, NULL);
}
fn = strdup("/tmp/alpm_XXXXXX");
fd = mkstemp(fn);
tar_extract_file(tar, fn);

View File

@ -23,17 +23,6 @@
#include <stdio.h>
#define MALLOC(p, b) { \
if((b) > 0) { \
p = malloc(b); \
if (!(p)) { \
fprintf(stderr, "malloc failure: could not allocate %d bytes\n", (b)); \
exit(1); \
} \
} else { \
p = NULL; \
} \
}
#define FREE(p) do { if (p) { free(p); p = NULL; } } while(0)
#define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0)