From ffe852d215b564b2fe674c141b71d7300dd56216 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Mon, 21 Jan 2008 10:48:27 +0200 Subject: [PATCH] Use m_malloc instead of malloc --- ChangeLog | 17 +++++++++++++++++ dpkg-deb/build.c | 6 +++--- dpkg-deb/extract.c | 4 +--- lib/mlib.c | 9 +++++---- lib/myopt.c | 6 ++---- lib/parse.c | 3 +-- lib/showpkg.c | 6 +++--- lib/tarfn.c | 20 +++++--------------- src/archives.c | 2 +- src/main.c | 14 +++----------- 10 files changed, 41 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0bd6ad65..5b48aacd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2008-01-21 Guillem Jover + + * dpkg-deb/build.c (getfi): Use m_malloc instead of malloc. + (do_build): Likewise. + * dpkg-deb/extract.c (extracthalf): Likewise. + * lib/mlib.c (buffer_write): Likewise. + (buffer_copy): Likewise. + * lib/myopt.c (loadcfgfile): Likewise. + * lib/parse.c (parsedb): Likewise. + * lib/showpkg.c (alloclstitem): Likewise. + (parsefield): Likewise. + (parsestring): Likewise. + * lib/tarfn.c (StoC): Likewise. + (TarExtractor): Likewise. + * src/archives.c (try_deconfigure_can): Likewise. + * src/main.c (execbackend): Likewise. + 2008-01-21 Guillem Jover * lib/mlib.c (m_strdup): New function. diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c index a38109c3..8e854b2f 100644 --- a/dpkg-deb/build.c +++ b/dpkg-deb/build.c @@ -101,7 +101,7 @@ static struct _finfo* getfi(const char* root, int fd) { if (fn == NULL) { fnlen = rl + MAXFILENAME; - fn=(char*)malloc(fnlen); + fn = m_malloc(fnlen); } else if (fnlen < (rl + MAXFILENAME)) { fnlen = rl + MAXFILENAME; fn=(char*)realloc(fn,fnlen); @@ -131,7 +131,7 @@ static struct _finfo* getfi(const char* root, int fd) { ohshit(_("file name '%.50s...' is too long"), fn + rl + 1); } - fi=(struct _finfo*)malloc(sizeof(struct _finfo)); + fi = m_malloc(sizeof(struct _finfo)); lstat(fn, &(fi->st)); fi->fn = m_strdup(fn + rl + 1); fi->next=NULL; @@ -193,7 +193,7 @@ void do_build(const char *const *argv) { /* template for our tempfiles */ if ((envbuf= getenv("TMPDIR")) == NULL) envbuf= P_tmpdir; - tfbuf = (char *)malloc(strlen(envbuf)+13); + tfbuf = m_malloc(strlen(envbuf) + 13); strcpy(tfbuf,envbuf); strcat(tfbuf,"/dpkg.XXXXXX"); subdir= 0; diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c index 760f0e60..1c20a04e 100644 --- a/dpkg-deb/extract.c +++ b/dpkg-deb/extract.c @@ -210,9 +210,7 @@ void extracthalf(const char *debar, const char *directory, (long) (stab.st_size - ctrllennum - strlen(ctrllenbuf) - l)) == EOF || fflush(stdout)) werr("stdout"); - ctrlarea = malloc(ctrllennum); - if (!ctrlarea) - ohshite(_("failed allocating memory for variable `ctrlarea'")); + ctrlarea = m_malloc(ctrllennum); errno=0; if (fread(ctrlarea,1,ctrllennum,ar) != ctrllennum) readfail(ar, debar, _("control area")); diff --git a/lib/mlib.c b/lib/mlib.c index da9b1dd8..a6eda5c1 100644 --- a/lib/mlib.c +++ b/lib/mlib.c @@ -171,7 +171,9 @@ off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc switch(data->type ^ BUFFER_WRITE_SETUP) { case BUFFER_WRITE_MD5: { - struct buffer_write_md5ctx *ctx = malloc(sizeof(struct buffer_write_md5ctx)); + struct buffer_write_md5ctx *ctx; + + ctx = m_malloc(sizeof(struct buffer_write_md5ctx)); ctx->hash = data->data.ptr; data->data.ptr = ctx; MD5Init(&ctx->ctx); @@ -187,7 +189,7 @@ off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc int i; unsigned char digest[16], *p = digest; struct buffer_write_md5ctx *ctx = (struct buffer_write_md5ctx *)data->data.ptr; - unsigned char *hash = *ctx->hash = malloc(33); + unsigned char *hash = *ctx->hash = m_malloc(33); MD5Final(digest, &ctx->ctx); for (i = 0; i < 16; ++i) { sprintf((char *)hash, "%02x", *p++); @@ -316,8 +318,7 @@ off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, off_t limit if((limit!=-1) && (limit < bufsize)) bufsize= limit; if(bufsize == 0) return 0; - writebuf= buf= malloc(bufsize); - if(buf== NULL) ohshite(_("failed to allocate buffer in buffer_copy (%s)"), desc); + writebuf = buf= m_malloc(bufsize); while(bytesread >= 0 && byteswritten >= 0 && bufsize > 0) { bytesread= read_data->proc(read_data, buf, bufsize, desc); diff --git a/lib/myopt.c b/lib/myopt.c index 84980a74..8275eec2 100644 --- a/lib/myopt.c +++ b/lib/myopt.c @@ -91,16 +91,14 @@ void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) { char *home, *file; int l1, l2; l1 = strlen(CONFIGDIR "/.cfg") + strlen(prog); - file = malloc(l1 + 1); - if (file==NULL) ohshite(_("Error allocating memory for cfgfilename")); + file = m_malloc(l1 + 1); sprintf(file, CONFIGDIR "/%s.cfg", prog); myfileopt(file, cmdinfos); if ((home = getenv("HOME")) != NULL) { l2 = strlen(home) + 1 + strlen("/.cfg") + strlen(prog); if (l2 > l1) { free(file); - file = malloc(l2 + 1); - if (file==NULL) ohshite(_("Error allocating memory for cfgfilename")); + file = m_malloc(l2 + 1); } sprintf(file, "%s/.%s.cfg", home, prog); myfileopt(file, cmdinfos); diff --git a/lib/parse.c b/lib/parse.c index 1a95cf96..28bd9e5f 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -115,8 +115,7 @@ int parsedb(const char *filename, enum parsedbflags flags, if ((dataptr= (char *)mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) ohshite(_("can't mmap package info file `%.255s'"),filename); #else - if ((dataptr= malloc(stat.st_size)) == NULL) - ohshite(_("failed to malloc for info file `%.255s'"),filename); + dataptr = m_malloc(stat.st_size); fd_buf_copy(fd, dataptr, stat.st_size, _("copy info file `%.255s'"),filename); #endif diff --git a/lib/showpkg.c b/lib/showpkg.c index 54db6098..9025807a 100644 --- a/lib/showpkg.c +++ b/lib/showpkg.c @@ -43,7 +43,7 @@ struct lstitem { static struct lstitem* alloclstitem(void) { struct lstitem* buf; - buf=(struct lstitem*)malloc(sizeof(struct lstitem)); + buf = m_malloc(sizeof(struct lstitem)); buf->type=invalid; buf->next=NULL; buf->data=NULL; @@ -81,7 +81,7 @@ static int parsefield(struct lstitem* cur, const char* fmt, const char* fmtend) } cur->type=field; - cur->data=(char*)malloc(len+1); + cur->data = m_malloc(len + 1); memcpy(cur->data, fmt, len); cur->data[len]='\0'; @@ -96,7 +96,7 @@ static int parsestring(struct lstitem* cur, const char* fmt, const char* fmtend) len=fmtend-fmt+1; cur->type=string; - write=cur->data=(char*)malloc(len+1); + write = cur->data = m_malloc(len + 1); while (fmt<=fmtend) { if (*fmt=='\\') { fmt++; diff --git a/lib/tarfn.c b/lib/tarfn.c index 3325d50e..0a96e75f 100644 --- a/lib/tarfn.c +++ b/lib/tarfn.c @@ -62,7 +62,7 @@ StoC(const char *s, int size) char * str; len = strnlen(s, size); - str = malloc(len + 1); + str = m_malloc(len + 1); memcpy(str, s, len); str[len] = 0; @@ -138,7 +138,7 @@ TarExtractor( next_long_name = NULL; next_long_link = NULL; long_read = 0; - symListBottom = symListPointer = symListTop = malloc(sizeof(symlinkList)); + symListBottom = symListPointer = symListTop = m_malloc(sizeof(symlinkList)); symListTop->next = NULL; h.UserData = userData; @@ -198,13 +198,8 @@ TarExtractor( memcpy(&symListBottom->h, &h, sizeof(TarInfo)); symListBottom->h.Name = m_strdup(h.Name); symListBottom->h.LinkName = m_strdup(h.LinkName); - if ((symListBottom->next = malloc(sizeof(symlinkList))) == NULL) { - free(symListBottom->h.LinkName); - free(symListBottom->h.Name); - status = -1; - errno = 0; - break; - } + symListBottom->next = m_malloc(sizeof(symlinkList)); + symListBottom = symListBottom->next; symListBottom->next = NULL; status = 0; @@ -225,12 +220,7 @@ TarExtractor( if (*longp) free(*longp); - if (NULL == (*longp = (char *)malloc(h.Size))) { - /* malloc failed, so bail */ - errno = 0; - status = -1; - break; - } + *longp = m_malloc(h.Size); bp = *longp; // the way the GNU long{link,name} stuff works is like this: diff --git a/src/archives.c b/src/archives.c index 60ee2d54..9fddb9c6 100644 --- a/src/archives.c +++ b/src/archives.c @@ -870,7 +870,7 @@ static int try_deconfigure_can(int (*force_p)(struct deppossi*), } } pkg->clientdata->istobe= itb_deconfigure; - newdeconf= malloc(sizeof(struct packageinlist)); + newdeconf = m_malloc(sizeof(struct packageinlist)); newdeconf->next= deconfigure; newdeconf->pkg= pkg; newdeconf->xinfo= removal; diff --git a/src/main.c b/src/main.c index 9ffc1613..b4bd50f4 100644 --- a/src/main.c +++ b/src/main.c @@ -489,26 +489,18 @@ void execbackend(const char *const *argv) { pass_admindir = 1; } - nargv = malloc(sizeof(char *) * (argc + 2)); - if (!nargv) - ohshite(_("couldn't malloc in execbackend")); - + nargv = m_malloc(sizeof(char *) * (argc + 2)); nargv[i] = m_strdup(cipaction->parg); i++, offset++; if (pass_admindir) { - nargv[i] = malloc((strlen("--admindir=") + strlen(admindir) + 1)); - if (!nargv[i]) - ohshite(_("couldn't malloc in execbackend")); - + nargv[i] = m_malloc((strlen("--admindir=") + strlen(admindir) + 1)); sprintf(nargv[i], "--admindir=%s", admindir); i++, offset++; } - nargv[i] = malloc(2 + strlen(cipaction->olong) + 1); - if (!nargv[i]) - ohshite(_("couldn't malloc in execbackend")); + nargv[i] = m_malloc(2 + strlen(cipaction->olong) + 1); strcpy(nargv[i], "--"); strcat(nargv[i], cipaction->olong); i++, offset++; -- 2.39.5