[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#74259: dpkg: a couple of memory leaks [PATCH]

Sorry for taking so long to respond.  Some of the suggestions in this bug
report have been put into dpkg long ago, but no response was ever given to
this bug.  Doing so now.

Please keep this bug open, until all ideas mentioned below are applied.

On Sat, 7 Oct 2000, Branden Robinson wrote:

> My next move was to cache the strings copied from Section lines rather
> than allocating fresh memory for each new Section line. This freed
> another 200k -- there are 79 unique sections but 5765 packages.

This has not yet been done in the current dpkg code base.  Do you(Paul) still
have the code you used to do this?

> Replacing nfstrsave("") in lib/parsehelp.c with a pointer to a static
> empty string saved another 130k. Taking "long double d" out of
> lib/nfmalloc.c's "union maxalign" saved another 850k. The largest type
> stored in nfmalloc space (by libdpkg) is a pointer.

nfstrsave("") is now put into a static var, and that is used over and over.

nfmalloc is now based in glibc obstacks, so the union thing no longer applies.

> Now, from my studying of the contents of lib/, the pool of nfmalloc
> memory should be approximately equal to the combined sizes of available
> and status (ie. 5.3MB). However the nfmalloc pool is nearly 6.8MB in
> size after my little tweaks. The difference amounts to about 275 bytes
> per package.
> Anybody want to speculate where the difference goes?

Nat at this time, no.

> (Passing comment: dselect is evil. It makes another copy of most of the
> data that's already in the data segment.)
> --- lib/fields.c~	Mon Oct 25 19:52:12 1999
> +++ lib/fields.c	Fri Oct  6 23:38:34 2000
> @@ -377,5 +377,6 @@
>      if (!*p) break;
>      p++; while (isspace(*p)) p++;
>    }
> +  varbuffree(&depname); varbuffree(&version);
>  }

This patch no longer is valid.  The function being manipulated above uses 2
static vars(depname and version), and saves their memory between calls.

> --- lib/dump.c~	Thu Oct 21 11:38:39 1999
> +++ lib/dump.c	Fri Oct  6 23:40:08 2000
> @@ -222,6 +222,7 @@
>    varbufaddc(&vb,'\0');
>    if (fputs(vb.buf,file) < 0)
>      ohshite("failed to write details of `%.50s' to `%.250s'", pigp->name, filename);
> +  varbuffree(&vb);
>  }
>  void writedb(const char *filename, int available, int mustsync) {

This has been part of dpkg for awhile now.

Reply to: