summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/alpm.h6
-rw-r--r--lib/libalpm/backup.c7
-rw-r--r--lib/libalpm/be_local.c14
-rw-r--r--lib/libalpm/be_package.c2
-rw-r--r--lib/libalpm/be_sync.c2
-rw-r--r--lib/libalpm/conflict.c17
-rw-r--r--lib/libalpm/db.c7
-rw-r--r--lib/libalpm/delta.c24
-rw-r--r--lib/libalpm/deps.c28
-rw-r--r--lib/libalpm/diskspace.c6
-rw-r--r--lib/libalpm/dload.c2
-rw-r--r--lib/libalpm/package.c11
-rw-r--r--lib/libalpm/package.h2
-rw-r--r--lib/libalpm/sync.c2
-rw-r--r--lib/libalpm/trans.c2
15 files changed, 99 insertions, 33 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index e6ef3ae3..91b94615 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1101,6 +1101,12 @@ int alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg);
*/
const char *alpm_pkg_get_filename(alpm_pkg_t *pkg);
+/** Returns the package base name.
+ * @param pkg a pointer to package
+ * @return a reference to an internal string
+ */
+const char *alpm_pkg_get_base(alpm_pkg_t *pkg);
+
/** Returns the package name.
* @param pkg a pointer to package
* @return a reference to an internal string
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index aeb41316..1fc5eb79 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -47,11 +47,10 @@ int _alpm_split_backup(const char *string, alpm_backup_t **backup)
*ptr = '\0';
ptr++;
/* now str points to the filename and ptr points to the hash */
- STRDUP((*backup)->name, str, return -1);
- STRDUP((*backup)->hash, ptr, return -1);
+ STRDUP((*backup)->name, str, FREE(str); return -1);
+ STRDUP((*backup)->hash, ptr, FREE(str); return -1);
FREE(str);
- return 0;
-}
+ return 0;}
/* Look for a filename in a alpm_pkg_t.backup list. If we find it,
* then we return the full backup entry.
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 93763966..0771aaf1 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -63,6 +63,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
* initialized.
*/
+static const char *_cache_get_base(alpm_pkg_t *pkg)
+{
+ LAZY_LOAD(INFRQ_DESC, NULL);
+ return pkg->base;
+}
+
static const char *_cache_get_desc(alpm_pkg_t *pkg)
{
LAZY_LOAD(INFRQ_DESC, NULL);
@@ -297,6 +303,7 @@ static int _cache_force_load(alpm_pkg_t *pkg)
* logic.
*/
static struct pkg_operations local_pkg_ops = {
+ .get_base = _cache_get_base,
.get_desc = _cache_get_desc,
.get_url = _cache_get_url,
.get_builddate = _cache_get_builddate,
@@ -701,6 +708,8 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
_alpm_log(db->handle, ALPM_LOG_ERROR, _("%s database is inconsistent: version "
"mismatch on package %s\n"), db->treename, info->name);
}
+ } else if(strcmp(line, "%BASE%") == 0) {
+ READ_AND_STORE(info->base);
} else if(strcmp(line, "%DESC%") == 0) {
READ_AND_STORE(info->desc);
} else if(strcmp(line, "%GROUPS%") == 0) {
@@ -801,6 +810,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
alpm_backup_t *backup;
CALLOC(backup, 1, sizeof(alpm_backup_t), goto error);
if(_alpm_split_backup(line, &backup)) {
+ FREE(backup);
goto error;
}
info->backup = alpm_list_add(info->backup, backup);
@@ -904,6 +914,10 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
free(path);
fprintf(fp, "%%NAME%%\n%s\n\n"
"%%VERSION%%\n%s\n\n", info->name, info->version);
+ if(info->base) {
+ fprintf(fp, "%%BASE%%\n"
+ "%s\n\n", info->base);
+ }
if(info->desc) {
fprintf(fp, "%%DESC%%\n"
"%s\n\n", info->desc);
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 5617f4fa..2d42465f 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -193,7 +193,7 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
STRDUP(newpkg->name, ptr, return -1);
newpkg->name_hash = _alpm_hash_sdbm(newpkg->name);
} else if(strcmp(key, "pkgbase") == 0) {
- /* not used atm */
+ STRDUP(newpkg->base, ptr, return -1);
} else if(strcmp(key, "pkgver") == 0) {
STRDUP(newpkg->version, ptr, return -1);
} else if(strcmp(key, "basever") == 0) {
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 52459483..6e89ad93 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -614,6 +614,8 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
if(_alpm_validate_filename(db, pkg->name, pkg->filename) < 0) {
return -1;
}
+ } else if(strcmp(line, "%BASE%") == 0) {
+ READ_AND_STORE(pkg->base);
} else if(strcmp(line, "%DESC%") == 0) {
READ_AND_STORE(pkg->desc);
} else if(strcmp(line, "%GROUPS%") == 0) {
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index db07102c..40cbb953 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -52,11 +52,15 @@ static alpm_conflict_t *conflict_new(alpm_pkg_t *pkg1, alpm_pkg_t *pkg2,
conflict->package1_hash = pkg1->name_hash;
conflict->package2_hash = pkg2->name_hash;
- STRDUP(conflict->package1, pkg1->name, return NULL);
- STRDUP(conflict->package2, pkg2->name, return NULL);
+ STRDUP(conflict->package1, pkg1->name, goto error);
+ STRDUP(conflict->package2, pkg2->name, goto error);
conflict->reason = reason;
return conflict;
+
+error:
+ alpm_conflict_free(conflict);
+ return NULL;
}
/**
@@ -79,11 +83,15 @@ alpm_conflict_t *_alpm_conflict_dup(const alpm_conflict_t *conflict)
newconflict->package1_hash = conflict->package1_hash;
newconflict->package2_hash = conflict->package2_hash;
- STRDUP(newconflict->package1, conflict->package1, return NULL);
- STRDUP(newconflict->package2, conflict->package2, return NULL);
+ STRDUP(newconflict->package1, conflict->package1, goto error);
+ STRDUP(newconflict->package2, conflict->package2, goto error);
newconflict->reason = conflict->reason;
return newconflict;
+
+error:
+ alpm_conflict_free(newconflict);
+ return NULL;
}
/**
@@ -284,6 +292,7 @@ static alpm_list_t *add_fileconflict(alpm_handle_t *handle,
return conflicts;
error:
+ alpm_fileconflict_free(conflict);
RET_ERR(handle, ALPM_ERR_MEMORY, conflicts);
}
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 466c96f1..0ca12d70 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -331,7 +331,7 @@ alpm_db_t *_alpm_db_new(const char *treename, int is_local)
alpm_db_t *db;
CALLOC(db, 1, sizeof(alpm_db_t), return NULL);
- STRDUP(db->treename, treename, return NULL);
+ STRDUP(db->treename, treename, FREE(db); return NULL);
if(is_local) {
db->status |= DB_STATUS_LOCAL;
} else {
@@ -542,7 +542,10 @@ alpm_pkghash_t *_alpm_db_get_pkgcache_hash(alpm_db_t *db)
}
if(!(db->status & DB_STATUS_PKGCACHE)) {
- load_pkgcache(db);
+ if(load_pkgcache(db)) {
+ /* handle->error set in local/sync-db-populate */
+ return NULL;
+ }
}
return db->pkgcache;
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index baa02b75..db6bb8e7 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -306,10 +306,10 @@ alpm_delta_t *_alpm_delta_parse(alpm_handle_t *handle, const char *line)
/* start at index 1 -- match 0 is the entire match */
len = pmatch[1].rm_eo - pmatch[1].rm_so;
- STRNDUP(delta->delta, &line[pmatch[1].rm_so], len, return NULL);
+ STRNDUP(delta->delta, &line[pmatch[1].rm_so], len, goto error);
len = pmatch[2].rm_eo - pmatch[2].rm_so;
- STRNDUP(delta->delta_md5, &line[pmatch[2].rm_so], len, return NULL);
+ STRNDUP(delta->delta_md5, &line[pmatch[2].rm_so], len, goto error);
len = pmatch[3].rm_eo - pmatch[3].rm_so;
if(len < sizeof(filesize)) {
@@ -319,12 +319,16 @@ alpm_delta_t *_alpm_delta_parse(alpm_handle_t *handle, const char *line)
}
len = pmatch[4].rm_eo - pmatch[4].rm_so;
- STRNDUP(delta->from, &line[pmatch[4].rm_so], len, return NULL);
+ STRNDUP(delta->from, &line[pmatch[4].rm_so], len, goto error);
len = pmatch[5].rm_eo - pmatch[5].rm_so;
- STRNDUP(delta->to, &line[pmatch[5].rm_so], len, return NULL);
+ STRNDUP(delta->to, &line[pmatch[5].rm_so], len, goto error);
return delta;
+
+error:
+ _alpm_delta_free(delta);
+ return NULL;
}
#undef NUM_MATCHES
@@ -342,14 +346,18 @@ alpm_delta_t *_alpm_delta_dup(const alpm_delta_t *delta)
{
alpm_delta_t *newdelta;
CALLOC(newdelta, 1, sizeof(alpm_delta_t), return NULL);
- STRDUP(newdelta->delta, delta->delta, return NULL);
- STRDUP(newdelta->delta_md5, delta->delta_md5, return NULL);
- STRDUP(newdelta->from, delta->from, return NULL);
- STRDUP(newdelta->to, delta->to, return NULL);
+ STRDUP(newdelta->delta, delta->delta, goto error);
+ STRDUP(newdelta->delta_md5, delta->delta_md5, goto error);
+ STRDUP(newdelta->from, delta->from, goto error);
+ STRDUP(newdelta->to, delta->to, goto error);
newdelta->delta_size = delta->delta_size;
newdelta->download_size = delta->download_size;
return newdelta;
+
+error:
+ _alpm_delta_free(newdelta);
+ return NULL;
}
/* vim: set noet: */
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index f2ee8f41..d105a324 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -50,11 +50,15 @@ static alpm_depmissing_t *depmiss_new(const char *target, alpm_depend_t *dep,
MALLOC(miss, sizeof(alpm_depmissing_t), return NULL);
- STRDUP(miss->target, target, return NULL);
+ STRDUP(miss->target, target, goto error);
miss->depend = _alpm_dep_dup(dep);
- STRDUP(miss->causingpkg, causingpkg, return NULL);
+ STRDUP(miss->causingpkg, causingpkg, goto error);
return miss;
+
+error:
+ alpm_depmissing_free(miss);
+ return NULL;
}
void SYMEXPORT alpm_depmissing_free(alpm_depmissing_t *miss)
@@ -469,7 +473,7 @@ alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
/* Note the extra space in ": " to avoid matching the epoch */
if((desc = strstr(depstring, ": ")) != NULL) {
- STRDUP(depend->desc, desc + 2, return NULL);
+ STRDUP(depend->desc, desc + 2, goto error);
deplen = desc - depstring;
} else {
/* no description- point desc at NULL at end of string for later use */
@@ -509,13 +513,17 @@ alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
}
/* copy the right parts to the right places */
- STRNDUP(depend->name, depstring, ptr - depstring, return NULL);
+ STRNDUP(depend->name, depstring, ptr - depstring, goto error);
depend->name_hash = _alpm_hash_sdbm(depend->name);
if(version) {
- STRNDUP(depend->version, version, desc - version, return NULL);
+ STRNDUP(depend->version, version, desc - version, goto error);
}
return depend;
+
+error:
+ alpm_dep_free(depend);
+ return NULL;
}
alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
@@ -523,13 +531,17 @@ alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
alpm_depend_t *newdep;
CALLOC(newdep, 1, sizeof(alpm_depend_t), return NULL);
- STRDUP(newdep->name, dep->name, return NULL);
- STRDUP(newdep->version, dep->version, return NULL);
- STRDUP(newdep->desc, dep->desc, return NULL);
+ STRDUP(newdep->name, dep->name, goto error);
+ STRDUP(newdep->version, dep->version, goto error);
+ STRDUP(newdep->desc, dep->desc, goto error);
newdep->name_hash = dep->name_hash;
newdep->mod = dep->mod;
return newdep;
+
+error:
+ alpm_dep_free(newdep);
+ return NULL;
}
/* These parameters are messy. We check if this package, given a list of
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index af87f755..c94cab31 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -112,7 +112,7 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle)
while((mnt = getmntent(fp))) {
CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
- STRDUP(mp->mount_dir, mnt->mnt_dir, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(mp->mount_dir, mnt->mnt_dir, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
mp->mount_dir_len = strlen(mp->mount_dir);
mount_points = alpm_list_add(mount_points, mp);
@@ -135,7 +135,7 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle)
while((ret = getmntent(fp, &mnt)) == 0) {
CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
- STRDUP(mp->mount_dir, mnt->mnt_mountp, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(mp->mount_dir, mnt->mnt_mountp, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
mp->mount_dir_len = strlen(mp->mount_dir);
mount_points = alpm_list_add(mount_points, mp);
@@ -162,7 +162,7 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle)
for(; entries-- > 0; fsp++) {
CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
- STRDUP(mp->mount_dir, fsp->f_mntonname, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(mp->mount_dir, fsp->f_mntonname, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
mp->mount_dir_len = strlen(mp->mount_dir);
memcpy(&(mp->fsp), fsp, sizeof(FSSTATSTYPE));
#if defined(HAVE_GETMNTINFO_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_FLAG)
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index e3409f99..c5186bef 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -379,7 +379,7 @@ static FILE *create_tempfile(struct dload_payload *payload, const char *localpat
payload->tempfile_name = randpath;
free(payload->remote_name);
STRDUP(payload->remote_name, strrchr(randpath, '/') + 1,
- RET_ERR(payload->handle, ALPM_ERR_MEMORY, NULL));
+ fclose(fp); RET_ERR(payload->handle, ALPM_ERR_MEMORY, NULL));
return fp;
}
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index d9ed3d31..b186a4cb 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -83,6 +83,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
* backend logic that needs lazy access, such as the local database through
* a lazy-load cache. However, the defaults will work just fine for fully-
* populated package structures. */
+static const char *_pkg_get_base(alpm_pkg_t *pkg) { return pkg->base; }
static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; }
static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; }
static alpm_time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; }
@@ -144,6 +145,7 @@ static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; }
* struct itself with no abstraction layer or any type of lazy loading.
*/
struct pkg_operations default_pkg_ops = {
+ .get_base = _pkg_get_base,
.get_desc = _pkg_get_desc,
.get_url = _pkg_get_url,
.get_builddate = _pkg_get_builddate,
@@ -186,6 +188,13 @@ const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg)
return pkg->filename;
}
+const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg)
+{
+ ASSERT(pkg != NULL, return NULL);
+ pkg->handle->pm_errno = 0;
+ return pkg->ops->get_base(pkg);
+}
+
const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
@@ -566,6 +575,7 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
newpkg->name_hash = pkg->name_hash;
STRDUP(newpkg->filename, pkg->filename, goto cleanup);
+ STRDUP(newpkg->base, pkg->base, goto cleanup);
STRDUP(newpkg->name, pkg->name, goto cleanup);
STRDUP(newpkg->version, pkg->version, goto cleanup);
STRDUP(newpkg->desc, pkg->desc, goto cleanup);
@@ -641,6 +651,7 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
}
FREE(pkg->filename);
+ FREE(pkg->base);
FREE(pkg->name);
FREE(pkg->version);
FREE(pkg->desc);
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 357c20ef..5ab9b207 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -43,6 +43,7 @@
* defined default_pkg_ops struct to work just fine for their needs.
*/
struct pkg_operations {
+ const char *(*get_base) (alpm_pkg_t *);
const char *(*get_desc) (alpm_pkg_t *);
const char *(*get_url) (alpm_pkg_t *);
alpm_time_t (*get_builddate) (alpm_pkg_t *);
@@ -85,6 +86,7 @@ extern struct pkg_operations default_pkg_ops;
struct __alpm_pkg_t {
unsigned long name_hash;
char *filename;
+ char *base;
char *name;
char *version;
char *desc;
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index c513b6b5..36646759 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -862,7 +862,7 @@ static struct dload_payload *build_payload(alpm_handle_t *handle,
struct dload_payload *payload;
CALLOC(payload, 1, sizeof(*payload), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
- STRDUP(payload->remote_name, filename, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(payload->remote_name, filename, FREE(payload); RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
payload->max_size = size;
payload->servers = servers;
return payload;
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 7cdb096f..e680feb3 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -343,7 +343,7 @@ int _alpm_runscriptlet(alpm_handle_t *handle, const char *filepath,
/* either extract or copy the scriptlet */
len += strlen("/.INSTALL");
- MALLOC(scriptfn, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
+ MALLOC(scriptfn, len, free(tmpdir); RET_ERR(handle, ALPM_ERR_MEMORY, -1));
snprintf(scriptfn, len, "%s/.INSTALL", tmpdir);
if(is_archive) {
if(_alpm_unpack_single(handle, filepath, tmpdir, ".INSTALL")) {