There is a memory leak in OPLCreate(),Should free allocated mem
before return.
Signed-off-by: Jidong Xia <xiajidong@cmss.chinamobile.com>
---
hw/audio/fmopl.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 9f50a89..ca9825b 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -1112,6 +1112,7 @@ FM_OPL *OPLCreate(int clock, int rate)
opl_dbg_maxchip++;
}
#endif
+ free(ptr);
return OPL;
}
--
1.8.3.1
On Wed, Oct 23, 2019 at 05:53:40PM +0800, Jidong Xia wrote: > There is a memory leak in OPLCreate(),Should free allocated mem > before return. > > Signed-off-by: Jidong Xia <xiajidong@cmss.chinamobile.com> > --- > hw/audio/fmopl.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c > index 9f50a89..ca9825b 100644 > --- a/hw/audio/fmopl.c > +++ b/hw/audio/fmopl.c > @@ -1112,6 +1112,7 @@ FM_OPL *OPLCreate(int clock, int rate) > opl_dbg_maxchip++; > } > #endif > + free(ptr); > return OPL; I don't know this code well, but I don't think is correct to free 'ptr' in the success case, since it is the pointer returned by this function that will be freed by OPLDestroy(). Does that sound right or did I miss something? Thanks, Stefano
On 10/24/19 4:25 AM, Stefano Garzarella wrote: > On Wed, Oct 23, 2019 at 05:53:40PM +0800, Jidong Xia wrote: >> There is a memory leak in OPLCreate(),Should free allocated mem >> before return. >> >> Signed-off-by: Jidong Xia <xiajidong@cmss.chinamobile.com> >> --- >> hw/audio/fmopl.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c >> index 9f50a89..ca9825b 100644 >> --- a/hw/audio/fmopl.c >> +++ b/hw/audio/fmopl.c >> @@ -1112,6 +1112,7 @@ FM_OPL *OPLCreate(int clock, int rate) >> opl_dbg_maxchip++; >> } >> #endif >> + free(ptr); >> return OPL; > > I don't know this code well, but I don't think is correct to free 'ptr' in > the success case, since it is the pointer returned by this function that > will be freed by OPLDestroy(). > > Does that sound right or did I miss something? ok, I understand it. > > Thanks, > Stefano > > Thanks, Jidong Xia
Patchew URL: https://patchew.org/QEMU/1571824420-24893-1-git-send-email-xiajidong@cmss.chinamobile.com/ Hi, This series seems to have some coding style problems. See output below for more information: Subject: [PATCH] hw/audio: fix a memory leak in OPLCreate() Type: series Message-id: 1571824420-24893-1-git-send-email-xiajidong@cmss.chinamobile.com === TEST SCRIPT BEGIN === #!/bin/bash git rev-parse base > /dev/null || exit 0 git config --local diff.renamelimit 0 git config --local diff.renames True git config --local diff.algorithm histogram ./scripts/checkpatch.pl --mailback base.. === TEST SCRIPT END === Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu - [tag update] patchew/20191023101956.19120-1-kraxel@redhat.com -> patchew/20191023101956.19120-1-kraxel@redhat.com * [new tag] patchew/20191024074307.22821-1-ganeshgr@linux.ibm.com -> patchew/20191024074307.22821-1-ganeshgr@linux.ibm.com Switched to a new branch 'test' 8f01555 hw/audio: fix a memory leak in OPLCreate() === OUTPUT BEGIN === ERROR: code indent should never use tabs #21: FILE: hw/audio/fmopl.c:1115: +^Ifree(ptr);$ total: 1 errors, 0 warnings, 7 lines checked Commit 8f01555c7bba (hw/audio: fix a memory leak in OPLCreate()) has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS. === OUTPUT END === Test command exited with code: 1 The full log is available at http://patchew.org/logs/1571824420-24893-1-git-send-email-xiajidong@cmss.chinamobile.com/testing.checkpatch/?type=message. --- Email generated automatically by Patchew [https://patchew.org/]. Please send your feedback to patchew-devel@redhat.com
© 2016 - 2024 Red Hat, Inc.