Project

General

Profile

Memory leak in the Postgres backend?

Added by David Betz about 11 years ago

I was looking over the postgres backend Postgres.C. I came across the following code:

  virtual void execute()
  {
    if (conn_.showQueries())
      std::cerr << sql_ << std::endl;

    if (!result_) {
      paramValues_ = new char *[params_.size()];

      for (unsigned i = 0; i < params_.size(); ++i) {
        if (params_[i].isbinary) {
          paramTypes_ = new int[params_.size() * 3];
          paramLengths_ = paramTypes_ + params_.size();
          paramFormats_ = paramLengths_ + params_.size();
          for (unsigned j = 0; j < params_.size(); ++j) {
            paramTypes_[j] = params_[j].isbinary ? BYTEAOID : 0;
            paramFormats_[j] = params_[j].isbinary ? 1 : 0;
            paramLengths_[j] = 0;
          }

          break;
        }
      }

My concern is with the line

          paramTypes_ = new int[params_.size() * 3];

What happens if there are 2 or more binary params? It seems that the new would be executed a second time, without deleting the previous allocation.

I have not tried to create an example, so this may just reflect a lack of understanding on my part.


Replies (1)

RE: Memory leak in the Postgres backend? - Added by David Betz about 11 years ago

Ooops, my bad. Now I see the break.

    (1-1/1)