Skip to content
This repository

Fix MySQL memory leak #1584

Merged
1 commit merged into from almost 2 years ago

3 participants

stintel Martijn Kaijser Sascha Montellese
stintel

Before commit 1f987e7, there were issues upgrading my music database to
the latest format (because of duplicate keys, which are solved by using
REPLACE instead of INSERT).

This pointed out a severe memory leak in
xbmc/dbwrappers/mysqldataset.cpp, which is confirmed by valgrind.

This is an attempt to fix the leak, and should solve #12459.

Martijn Kaijser

@Montellese
Your territory

Sascha Montellese
Collaborator

Not really, I don't even have a mysql setup so can't check if there's really a memory leak or not (but looking at the fix it might well be).

Deleted user

now squash the commits ;)

stintel stintel Fix MySQL memory leak
Before commit 1f987e7, there were issues upgrading my music database to
the latest format (because of duplicate keys, which are solved by using
REPLACE instead of INSERT).

This pointed out a severe memory leak in
xbmc/dbwrappers/mysqldataset.cpp, which is confirmed by valgrind.

This is an attempt to fix the leak, and should solve #12459.
f102080
Deleted user ghost merged commit 13d597c into from
Deleted user ghost closed this
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 09, 2012
stintel stintel Fix MySQL memory leak
Before commit 1f987e7, there were issues upgrading my music database to
the latest format (because of duplicate keys, which are solved by using
REPLACE instead of INSERT).

This pointed out a severe memory leak in
xbmc/dbwrappers/mysqldataset.cpp, which is confirmed by valgrind.

This is an attempt to fix the leak, and should solve #12459.
f102080
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 14 additions and 0 deletions. Show diff stats Hide diff stats

  1. +14 0 xbmc/dbwrappers/mysqldataset.cpp
14 xbmc/dbwrappers/mysqldataset.cpp
@@ -240,7 +240,10 @@ int MysqlDatabase::copy(const char *backup_name) {
240 240 // create the new database
241 241 sprintf(sql, "CREATE DATABASE `%s`", backup_name);
242 242 if ( (ret=query_with_reconnect(sql)) != MYSQL_OK )
  243 + {
  244 + mysql_free_result(res);
243 245 throw DbErrors("Can't create database for copy: '%s' (%d)", db.c_str(), ret);
  246 + }
244 247
245 248 MYSQL_ROW row;
246 249
@@ -252,15 +255,22 @@ int MysqlDatabase::copy(const char *backup_name) {
252 255 backup_name, row[0], row[0]);
253 256
254 257 if ( (ret=query_with_reconnect(sql)) != MYSQL_OK )
  258 + {
  259 + mysql_free_result(res);
255 260 throw DbErrors("Can't copy schema for table '%s'\nError: %s", db.c_str(), ret);
  261 + }
256 262
257 263 // copy the table data
258 264 sprintf(sql, "INSERT INTO %s.%s SELECT * FROM %s",
259 265 backup_name, row[0], row[0]);
260 266
261 267 if ( (ret=query_with_reconnect(sql)) != MYSQL_OK )
  268 + {
  269 + mysql_free_result(res);
262 270 throw DbErrors("Can't copy data for table '%s'\nError: %s", row[0], ret);
  271 + }
263 272 }
  273 + mysql_free_result(res);
264 274
265 275 // after table are recreated and repopulated we can recreate views
266 276 // grab a list of views and their definitions
@@ -279,7 +289,10 @@ int MysqlDatabase::copy(const char *backup_name) {
279 289 backup_name, row[0], row[1]);
280 290
281 291 if ( (ret=query_with_reconnect(sql)) != MYSQL_OK )
  292 + {
  293 + mysql_free_result(resViews);
282 294 throw DbErrors("Can't create view '%s'\nError: %s", db.c_str(), ret);
  295 + }
283 296 }
284 297 mysql_free_result(resViews);
285 298 }
@@ -336,6 +349,7 @@ long MysqlDatabase::nextid(const char* sname) {
336 349 lengths = mysql_fetch_lengths(res);
337 350 CLog::Log(LOGINFO,"Next id is [%.*s] ", (int) lengths[0], row[0]);
338 351 sprintf(sqlcmd,"update %s set nextid=%d where seq_name = '%s'",seq_table,id,sname);
  352 + mysql_free_result(res);
339 353 if ((last_err = query_with_reconnect(sqlcmd) != 0)) return DB_UNEXPECTED_RESULT;
340 354 return id;
341 355 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.