diff options
author | rjray <devnull@localhost> | 2002-05-10 07:37:08 +0000 |
---|---|---|
committer | rjray <devnull@localhost> | 2002-05-10 07:37:08 +0000 |
commit | 5a5b62e9c14f51d430c11642e05d77052c223ee8 (patch) | |
tree | 51bf4aedd4f3d02941e168a8c6c7ea0608f43f63 | |
parent | 97aaa7f141caf7f1a00808cac245ce93c7cbc365 (diff) | |
download | librpm-tizen-5a5b62e9c14f51d430c11642e05d77052c223ee8.tar.gz librpm-tizen-5a5b62e9c14f51d430c11642e05d77052c223ee8.tar.bz2 librpm-tizen-5a5b62e9c14f51d430c11642e05d77052c223ee8.zip |
Changed some safemalloc calls to New/Newz. Put a fix in FIRSTKEY to avoid
getting a null back from the initial tag look-up. Cause DESTROY to free some
memory that was being forgotten. Pulled out all the 3.0 and pre-4.0.3 support
code.
CVS patchset: 5428
CVS date: 2002/05/10 07:37:08
-rw-r--r-- | Perl-RPM/RPM/Header.xs | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/Perl-RPM/RPM/Header.xs b/Perl-RPM/RPM/Header.xs index db754a90e..cefef065c 100644 --- a/Perl-RPM/RPM/Header.xs +++ b/Perl-RPM/RPM/Header.xs @@ -8,7 +8,7 @@ # define RPMERR_READERROR RPMERR_READ #endif -static char * const rcsid = "$Id: Header.xs,v 1.25 2002/04/11 23:06:01 rjray Exp $"; +static char * const rcsid = "$Id: Header.xs,v 1.26 2002/05/10 07:37:08 rjray Exp $"; static int scalar_tag(pTHX_ SV *, int); /* @@ -250,7 +250,7 @@ static int new_from_fname(pTHX_ const char* source, RPM_Header* new_hdr) if ((retval = new_from_fd_t(fd, new_hdr))) { Fclose(fd); - new_hdr->source_name = safemalloc(strlen(source) + 1); + New(0, new_hdr->source_name, strlen(source) + 1, char); strcpy(new_hdr->source_name, source); } @@ -265,8 +265,7 @@ RPM__Header rpmhdr_TIEHASH(pTHX_ char* class, SV* source, int flags) RPM_Header* retvalp; /* Use this to store the actual C-level data */ SV* t_magic; - retvalp = new_RPM_storage(RPM_Header); - Zero(retvalp, 1, RPM_Header); + Newz(0, retvalp, 1, RPM_Header); RETVAL = Nullhv; if (! source) @@ -355,7 +354,7 @@ SV* rpmhdr_FETCH(pTHX_ RPM__Header self, SV* key, if (! (name && (namelen = strlen(name)))) return FETCH; - uc_name = safemalloc(namelen + 3); + New(0, uc_name, namelen+3, char); for (i = 0; i < namelen; i++) uc_name[i] = toUPPER(name[i]); uc_name[i] = '\0'; @@ -453,7 +452,7 @@ int rpmhdr_STORE(pTHX_ RPM__Header self, SV* key, SV* value) if (! (name && (namelen = strlen(name)))) return 0; - uc_name = safemalloc(namelen + 3); + New(0, uc_name, namelen+3, char); for (i = 0; i < namelen; i++) uc_name[i] = toUPPER(name[i]); uc_name[i] = '\0'; @@ -730,7 +729,7 @@ int rpmhdr_STORE(pTHX_ RPM__Header self, SV* key, SV* value) else cloned = sv_mortalcopy(*svp); str_sv = SvPV(cloned, len); - str_new = safemalloc(len + 1); + New(0, str_new, len+1, char); strncpy(str_new, str_sv, len + 1); } else @@ -752,7 +751,7 @@ int rpmhdr_STORE(pTHX_ RPM__Header self, SV* key, SV* value) else cloned = sv_mortalcopy(*svp); str_sv = SvPV(*svp, len); - str_new = safemalloc(len + 1); + New(0, str_new, len+1, char); strncpy(str_new, str_sv, len + 1); data_p[i] = str_new; } @@ -798,7 +797,7 @@ int rpmhdr_DELETE(pTHX_ RPM__Header self, SV* key) if (! (name && (namelen = strlen(name)))) return 0; - uc_name = safemalloc(namelen + 3); + New(0, uc_name, namelen+3, char); for (i = 0; i < namelen; i++) uc_name[i] = toUPPER(name[i]); uc_name[i] = '\0'; @@ -846,7 +845,7 @@ bool rpmhdr_EXISTS(pTHX_ RPM__Header self, SV* key) return 0; /* Unlike FETCH, there will be no need for the KEY_t string */ - uc_name = safemalloc(namelen + 1); + New(0, uc_name, namelen+1, char); for (i = 0; i < namelen; i++) uc_name[i] = toUPPER(name[i]); uc_name[i] = '\0'; @@ -888,12 +887,19 @@ int rpmhdr_FIRSTKEY(pTHX_ RPM__Header self, SV** key, SV** value) /* Run once to get started */ headerNextIterator(hdr->iterator, Null(int *), Null(int *), Null(const void **), Null(int *)); - /* Now run it once, to get the first header entry */ - if (! headerNextIterator(hdr->iterator, &tag, &type, (const void **)&ptr, - &size)) - return 0; + while (1) + { + /* Run it to get the header entry */ + if (! headerNextIterator(hdr->iterator, &tag, &type, + (const void **)&ptr, &size)) + return 0; + + tagname = num2tag(aTHX_ tag); + /* If the one we've just gotten is null, loop */ + if (tagname != Nullch) + break; + } - tagname = num2tag(aTHX_ tag); *key = newSVpv((char *)tagname, strlen(tagname)); *value = rpmhdr_FETCH(aTHX_ self, *key, ptr, type, size); @@ -948,6 +954,8 @@ void rpmhdr_DESTROY(pTHX_ RPM__Header self) headerFree(hdr->hdr); hv_undef(hdr->storage); + if (hdr->source_name) + Safefree(hdr->source_name); Safefree(hdr); hv_undef(self); } @@ -979,7 +987,7 @@ int rpmhdr_tagtype(pTHX_ RPM__Header self, SV* key) if (! (name && (namelen = strlen(name)))) return RPM_NULL_TYPE; - uc_name = safemalloc(namelen + 3); + New(0, uc_name, namelen+3, char); for (i = 0; i < namelen; i++) uc_name[i] = toUPPER(name[i]); uc_name[i] = '\0'; @@ -1363,7 +1371,7 @@ rpmhdr_scalar_tag(self, tag) RETVAL = 0; else { - uc_name = safemalloc(namelen + 1); + New(0, uc_name, namelen+1, char); for (i = 0; i < namelen; i++) uc_name[i] = toUPPER(name[i]); uc_name[i] = '\0'; |